Launch Chrome Browser / Safari Browser:
1. Launch Chrome Browser using Selenium
- WebDrivers for different browsers: FirefoxDriver() for Firefox browser, ChromeDriver() for Google Chrome, SafariDriver() for Safari Browser, InternetExplorerDriver for Internet Explorer etc.
- Webdriver is an Interface and ChromeDriver() is a class which has implemented Webdriver Interface.
- Interface, there is a set of variables and methods without any body (no implementation, only method name and signature). We can not instantiate objects from the interface.
- WebDriver is an interface which contains all the unimplemented common methods, which can be used for any browser e.g. getTitle(), getCurrentUrl(), get(), findElement() etc.
Download ChromeDriver.exe:
- Download the latest ChromeDriver binary from the Chromium.org download page and be executable on your local machine.
- Set Webdriver.chrome.driver property to chromeDriver.exe instead.
- System.setProperty (“webdriver.chrome.driver”, “chromeDriver.exe path”);
Launching Chrome Browser:
1 2 3 4 5 | // Set System Property for Chrome with ChromeDriver.exe path System.setProperty("webdriver.chrome.driver","Pathchromedriver.exe"); //Creating a driver object referencing WebDriver interface WebDriver driver = new ChromeDriver(); |
Example of Launching Chrome Browser:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // Importing Packages import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class ChromeDriver{ public static void main(String[] args) { // Set chromedriver path System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe"); //Creating a driver object referencing WebDriver interface WebDriver driver = new ChromeDriver(); // Open URL into chrome browser driver.get("https://www.stqatools.com"); // Get Title Text and print System.out.println("Title is :-"+driver.getTitle()); // Close Chrome browser driver.close(); } } |
Output:
1 | Title is :- Software Testing Quality Automation Tutorials |
Importing Packages:
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.chrome.ChromeDriver;
- Using Above packages selenium launch chrome browser.
2. Launch Safari Browser using Selenium
- WebDrivers for different browsers: FirefoxDriver() for Firefox browser, ChromeDriver() for Google Chrome, SafariDriver() for Safari Browser, InternetExplorerDriver for Internet Explorer etc.
- Webdriver is an Interface and SafariDriver() is a class which has implemented Webdriver Interface.
- WebDriver is an interface which contains all the unimplemented common methods, which can be used for any browser e.g. getTitle(), getCurrentUrl(), get(), findElement() etc.
- The Safari browser does not require any additional configuration and can be launched immediately with the Safari driver.
launching Safari browser:
1 2 | //Creating a driver object referencing WebDriver interface of SafariDriver WebDriver driver = new SafariDriver(); |
Example of launching Safari browser:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | // Importing Packages import org.openqa.selenium.WebDriver; import org.openqa.selenium.safari.SafariDriver; public class SafariDriver{ public static void main(String[] args) { //Creating a driver object referencing WebDriver interface WebDriver driver = new SafariDriver(); // Open Website in newly launch safari browser driver.get("https://www.stqatools.com"); System.out.println("Title is :-"+driver.getTitle()); // Close instance of Safari browser driver.close(); } } |
Output:
1 | Title is :- Software Testing Quality Automation Tutorials |
Importing Packages:
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.safari.SafariDriver;
- Using Above packages selenium launch Safari browser.
chrome browser automation and selenium webdriver chrome driver and how to download chromedriver and selenium webdriver chrome or selenium webdriver chrome