How To Run Test Cases Using Google Chrome In Selenium Automation Script

To run google chrome in your selenium webdriver automation script, like IE Driver server, you need a ChromeDriver.exe executable file also. The theory is same as IE, this driver also startup a server, and waiting for selenium commands come from webdriver scripts.

How to use chromedriver

First you need to download the latest version in following page.

Download the latest version,
selenium chrome driver download page

Save download file to somewhere like C:\Workspace\\Lib. Unzip the zip file in the Lib folder. You can see chromedriver.exe file under C:\Workspace\\Lib\chromedriver_win32. save chrome driver in your local directory

Now you can start to write java code using it.

Starting web browser with Selenium WebDriver

You need two steps in your java code to start google web browser.

1. Specify system property “”’s value to your downloaded Driver executiable file path.
2. Create a new instance of ChromeDriver class.

Following is the example code that can do above steps. You can see comments for each line of code to understand it.

 //Set string variable value to Chrome Driver executable file path.
 String chromeDriverPath = "C:\\Workspace\\\\Lib\\chromedriver_win32\\chromedriver.exe";
 //Assign chromeDriverPath to system property ""
 System.setProperty("", chromeDriverPath);
 //Initiate a new instance
 ChromeDriver cDriver = new ChromeDriver();
 * Browser webpage using the new created chrome driver instance.
 * You should add http:// protocal before otherwise there will have an exception occured
 //Quit web browser

Key Points

  1. When you use any web browser (chrome, IE or Firefox) to browse web page you need to add http:// before the domain name, otherwise an exception will be thrown.
  2. If you meet following compile error message “ChromeDriver cannot be resolved to a type”,  you need import that class into your java code. You just need to press “ctrl+shift+o” to import all the classes needed in your java code.
    cannot be resolved to a type in java

[download id=”326″]

0 0 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x