❅
❅
❆
❅
❆
❅
❆
❅
❆
❆

  • 0939206009
  • thaian.it15@gmail.com
  • Facebook
  • Youtube
  • Zalo
Anh Tester Logo
  • Khoá học
    • All Courses
    • Website Testing
    • API Testing
    • Desktop Testing
    • Mobile Testing
    • Programming Language
    • CI/CD for Tester
    • Performance Testing
  • 💥Khai giảng
  • tools
    • TestGenAI - AI Test Cases Generator
    • Mobile Apps Demo
    • Automation Framework Selenium TestNG
    • Automation Framework Cucumber TestNG
    • Gherkin Convert Functions in Katalon
    • Convert object from Selenium Java to Playwright Python
    • Website Demo CRM
    • Website Demo HRM
    • Website Demo HRM GO
    • Website Demo POS
    • Website Demo eCommerce CMS
  • blog
    • Selenium C#
    • Selenium Java
    • Katalon Tools
    • Jenkins CI/CD
    • SQL cho Tester
    • Manual Testing
    • Tài liệu cho Tester
    • Automation Testing
    • akaAT Tools
    • Cucumber TestNG
    • API Testing with Postman
    • Apache Maven
    • AI in Software Testing
    • Lịch khai giảng
  • Liên hệ
  • Log in
    Sign up

Khởi chạy các loại trình duyệt trong Selenium

  • Blog
  • Automation Testing
Khởi chạy các loại trình duyệt trong Selenium

Khởi chạy các loại trình duyệt trong Selenium

  • Anh Tester
  • Automation Testing
  • 10195

Trong bài viết này Anh Tester sẽ giới thiệu chi tiết các lệnh Selenium WebDriver được sử dụng để khởi chạy các loại trình duyệt. Chúng ta cũng sẽ tìm hiểu các tùy chỉnh bổ sung khác nhau cần thiết để khởi chạy một số trình duyệt nhất định như Chrome, Firefox và InternetExplorer...

  • Khởi chạy trình duyệt Firefox
  • Khởi chạy trình duyệt Chrome
  • Khởi chạy trình duyệt Internet Explorer
  • Khởi chạy trình duyệt Microsoft Edge
  • Khởi chạy trình duyệt Safari
  • Khởi chạy trình duyệt Opera


Khởi chạy trình duyệt Firefox

Firefox là một trong những trình duyệt được sử dụng rộng rãi nhất trong lĩnh vực tự động hóa. Các bước sau là bắt buộc để khởi chạy trình duyệt firefox.

  1. Tải xuống geckodriver.exe từ trang phát hành GeckoDriver Github . Đảm bảo tải xuống tệp trình điều khiển phù hợp dựa trên nền tảng và phiên bản hệ điều hành của bạn.
  2. Thiết đặt thuộc tính hệ thống với giá trị “webdriver.gecko.driver” và đường dẫn geckodriver.exe như sau:
    System.setProperty ("webdriver.gecko.driver", "/resourses/driver/geckodriver.exe");


Đoạn mã để khởi chạy trình duyệt Firefox:

public class FirefoxBrowserLaunchDemo {
  public static void main(String[] args) {

    //Creating a driver object referencing WebDriver interface
    WebDriver driver;

    //Setting webdriver.gecko.driver property
    System.setProperty("webdriver.gecko.driver", "/resourses/driver/geckodriver.exe");

    //Instantiating driver object and launching browser
    driver = new FirefoxDriver();

    //Using get() method to open a webpage
    driver.get("https://anhtester.com");

    //Closing the browser
    driver.quit();

  }
}


Note: nếu dùng Selenium 4 bản mới nhất thì không cần dòng code System.setProperty nhé

 

Khởi chạy trình duyệt Chrome

Để chạy trình duyệt Chrome trong Selenium, chúng ta cần đặt thuộc tính hệ thống webdriver.chrome.driver trỏ đến tệp thực thi trình điều khiển Chrome:

  1. Tải xuống tệp nhị phân chromedriver.exe mới nhất từ Chrome for Testing stable và đặt tệp thực thi trên máy cục bộ của bạn.
  2. Đặt thuộc tính như sau:
    System.setProperty("webdriver.chrome.driver", "/resourses/driver/chromedriver.exe");​


Đoạn mã để khởi chạy trình duyệt Chrome:

public class ChromeBrowserLaunchDemo {
  public static void main(String[] args) {

    //Creating a driver object referencing WebDriver interface
    WebDriver driver;

    //Setting the webdriver.chrome.driver property to its executable's location
    System.setProperty("webdriver.chrome.driver", "/resourses/driver/chromedriver.exe");

    //Instantiating driver object
    driver = new ChromeDriver();

    //Using get() method to open a webpage
    driver.get("https://anhtester.com");

    //Closing the browser
    driver.quit();

  }
}

 

Note: nếu dùng Selenium 4 bản mới nhất thì không cần dòng code System.setProperty nhé

 

Khởi chạy trình duyệt Internet Explorer

Giống như ChromeDriver, trình điều khiển Internet Explorer cũng yêu cầu thiết lập thuộc tính “webdriver.ie.driver”

System.setProperty("webdriver.ie.driver", "/resourses/driver/IEDriverServer.exe");

IEDriverServer.exe có thể được tải xuống từ  đây . (từ v3.9 đổ lại thôi. Mà giờ ai dùng IE làm gì, nên bỏ đi)

Đoạn mã sau được sử dụng để khởi chạy trình duyệt IE:

public class IEBrowserLaunchDemo {
  public static void main(String[] args) {

    //Creating a driver object referencing WebDriver interface
    WebDriver driver;

    //Setting the webdriver.ie.driver property to its executable's location
    System.setProperty("webdriver.ie.driver", "/resourses/driver/IEDriverServer.exe");

    //Instantiating driver object
    driver = new InternetExplorerDriver();

    //Using get() method to open a webpage
    driver.get("https://anhtester.com");

    //Closing the browser
    driver.quit();

  }
}

 

Khởi chạy trình duyệt Microsoft Edge

Trình điều khiển Microsoft Edge yêu cầu thiết lập thuộc tính “webdriver.edge.driver” với vị trí của msedgedriver.exe

System.setProperty("webdriver.edge.driver", "/resourses/driver/msedgedriver.exe");

 

và có thể tải msedgedriver.exe xuống từ  đây .

Đoạn mã sau được sử dụng để khởi chạy trình duyệt Edge:

public class EdgeBrowserLaunchDemo {
  public static void main(String[] args) {

    //Creating a driver object referencing WebDriver interface
    WebDriver driver;

    //Setting the webdriver.edge.driver property to its executable's location
    System.setProperty("webdriver.edge.driver", "/resourses/driver/msedgedriver.exe");

    //Instantiating driver object
    driver = new EdgeDriver();

    //Using get() method to open a webpage
    driver.get("https://anhtester.com");

    //Closing the browser
    driver.quit();

  }
}


Note: nếu dùng Selenium 4 bản mới nhất thì không cần dòng code System.setProperty nhé

 

Khởi chạy trình duyệt Safari

Trình duyệt Safari trên máy tính Macbook không yêu cầu bất kỳ cấu hình bổ sung nào và có thể được khởi chạy trực tiếp bằng cách tạo với SafariDriver.

Đoạn mã sau được sử dụng để khởi chạy trình duyệt Safari:

public class SafariBrowserLaunchDemo {
    public static void main(String[] args) {

        //Creating a driver object referencing WebDriver interface
        WebDriver driver;

        //Instantiating driver object with SafariDriver
        driver = new SafariDriver();

        //Using get() method to open a webpage
        driver.get("https://anhtester.com");

        //Closing the browser
        driver.quit();
    }
}

 

Khởi chạy trình duyệt Opera

Để chạy trình duyệt Opera trong Selenium, chúng ta cần đặt thuộc tính hệ thống webdriver.opera.driver trỏ đến tệp thực thi trình điều khiển Opera

  1. Tải xuống tệp nhị phân OperaDriver.exe mới nhất từ  trang tải xuống OperaDriver  và đặt tệp thực thi trên máy cục bộ của bạn.
  2. Đặt thuộc tính như sau:
    System.setProperty("webdriver.opera.driver", "/resourses/driver/operadriver.exe");​


Đoạn mã để khởi chạy trình duyệt Opera:

public class OperaBrowserLaunchDemo {
  public static void main(String[] args) {

    //Creating a driver object referencing WebDriver interface
    WebDriver driver;

    System.setProperty("webdriver.opera.driver", "/resourses/driver/operadriver.exe");
    
    driver = new OperaDriver();
    
    driver.get("https://anhtester.com/");

    //Closing the browser
    driver.quit();

  }
}


Đó là những trình duyệt mà Anh Tester giới thiệu đến các bạn trong bài viết này, nếu bạn có bất kỳ thắc mắc nào có thể comment bên dưới hoặc join group hỏi đáp thêm.

Bạn có thể xem thêm khóa Selenium Java hoặc Selenium C# tại đây.

  • Tags:
  • trình duyệt
  • browser
  • selenium

Chia sẻ bài viết

Facebook Linkedin Telegram Pinterest Share with Zalo Zalo

Cộng đồng Automation Testing Việt Nam

🌱 Facebook Fanpage: Anh Tester
🌱 Telegram
Automation Testing:   Cộng đồng Automation Testing
🌱 
Facebook Group Automation: Cộng đồng Automation Testing Việt Nam
🌱 Telegram
Manual Testing:   Cộng đồng Manual Testing
🌱 
Facebook Group Manual: Cộng đồng Manual Testing Việt Nam

  • Anh Tester

    Anh Tester

    Đường dẫu khó chân vẫn cần bước đi
    Đời dẫu khổ tâm vẫn cần nghĩ thấu

    • Facebook
    • Youtube
    • Zalo

Search Blogs

Related Blogs

🤖 So sánh Playwright JS/TS và Playwright Python

🤖 So sánh Playwright JS/TS và Playwright Python

Aug-29-2025 by Anh Tester
So sánh Playwright và Selenium trong Test Automation

So sánh Playwright và Selenium trong Test Automation

Aug-23-2025 by Anh Tester
🚀 Lộ trình học Automation Tester tại Anh Tester

🚀 Lộ trình học Automation Tester tại Anh Tester

Aug-23-2025 by Anh Tester
Những kỹ năng cần có cho level Senior Automation Tester

Những kỹ năng cần có cho level Senior Automation Tester

Dec-17-2024 by Anh Tester
Những kỹ năng cần có cho level Middle Automation Tester

Những kỹ năng cần có cho level Middle Automation Tester

Dec-17-2024 by Anh Tester
Những kỹ năng cần có cho level Junior Automation Tester

Những kỹ năng cần có cho level Junior Automation Tester

Dec-17-2024 by Anh Tester
Những kỹ năng cần có cho level Fresher Automation Tester

Những kỹ năng cần có cho level Fresher Automation Tester

Dec-17-2024 by Anh Tester
Cách xử lý các Exceptions trong Selenium WebDriver

Cách xử lý các Exceptions trong Selenium WebDriver

May-31-2024 by Anh Tester
Tại sao chúng ta cần Kiểm thử Tự động

Tại sao chúng ta cần Kiểm thử Tự động

May-30-2024 by Anh Tester
How to get HTML5 validation message with Selenium

How to get HTML5 validation message with Selenium

Mar-22-2024 by Anh Tester
view all

Blog Tags

  • Selenium
  • Xpath
  • Locator
  • Jenkins
  • Testing
  • Tester
  • Thuật ngữ
  • Lộ trình
  • Khóa học
  • Mindset
  • QA
  • QC
  • Checklist
  • Website
  • Mobile
  • Question
  • Answer
  • Phỏng vấn
  • Extension
  • Cucumber
  • Gherkin
  • Agile
  • Scrum
  • Document
  • Testing Level
  • Automation Test
  • Test Cases
  • Trường hợp
  • Katalon
  • JMeter
  • Postman
  • API
  • Manual Test
  • Developer

Anh Tester

Anh Tester profile
Đường dẫu khó chân vẫn cần bước đi
Đời dẫu khổ tâm vẫn cần nghĩ thấu

Connect me on

  • Facebook
  • Youtube
  • Zalo


Liên hệ

  • 0939206009
  • thaian.it15@gmail.com
  • Anh Tester
  • Donate for Anh Tester
QR Facebook Group
QR Discord Group

Copyright © 2021-2025 Anh Tester Automation Testing