Selenium automates browsers like Firefox,Chrome and Internet Explorer.
Selenium WebDriver Scripts run against multiple Platforms MAC,Windows and Linux.
In this tutorial, we will discuss about Running Selenium WebDriver Scripts on Chrome Browser.
Steps to be Followed to Execute Tests on Chrome Browser
1. Access the URL http://seleniumhq.org and navigate to the Downloads tab.
2. Click on the Download Link the Latest version of Selenium Jars.
3. Unzip the selenium-java-3.xx.0.zip file and view the contents of the Jar files.
4. Open Eclipse->Right Click on Java Project->Build Path->Configure Build Path.
5. Click on ‘External Jars’ button and navigate to the directory where the Selenium Webdriver jars are unzipped in previous Step 3.
6. Add the External Jar – client-combined-3.xx.0.jar.
7. Add the External Jars available under lib folder unzipped in Step 3.
Update Chrome Browser
1. On your computer, open Chrome browser.
2. At the top right, click More as shown in the below screenshot.
3. Click Update Google Chrome. If you don’t see this button, you’re on the latest version.
4. Click Relaunch and verify the Chrome Browser updated to the Latest version.
Download the chromedriver.exe and copy to Java Project.
1. Download the Latest Version of Chrome Driver Executable File from this link.
http://chromedriver.chromium.org/downloads
2. Download the Zip file according the Operating System-Windows,MAC,Linux.
Note: For Windows, 64 bit version is not available.
3. Unzip the File and look for chromedriver.exe.
4. Right Click and copy the chromedriver.exe downloaded.
5. Open Eclipse and Right Click on the project in the package explorer and copy the Executable file in
the Java Project.
Example Program
1 2 3 4 5 6 7 8 9 10 |
public class ChromeDriverTests { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","chromedriver.exe"); ChromeDriver driver = new ChromeDriver(); driver.get("http://total-qa.com"); System.out.println(driver.getTitle()); } } |
Console Output
To disable the Information Logs in the console
Firefox:
Add the below statement before instantiating the Firefox Driver instance.
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,“null");
Chrome Browser
Add the below statements before instantiating driver instance.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--log-level=3");
chromeOptions.addArguments("--silent");
WebDriver driver = new ChromeDriver(chromeOptions);