Have you experienced this Exception when starting your Selenium test for the first time with the Chrome WebDriver?

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html

The reason is probably that you have not told your system where to find your driver executable. Unlike when using the Firefox WebDriver you need to download a driver executable which is specifically for Chrome and builds the the conncection part between your Java Selenium program and the Chrome Webbrowser.

To fix this problem follow these steps:

  1. Download the latest ChromeDriver for your operating system here. If you work with windows choose “chromedriver_win32.zip”.
  2. Extract the content of the zip file (chromedriver.exe) to any place on your computer, that you will remember later.
  3. After replacing the location of the chromedriver.exe with the specific location on your computer, add the following code to your Selenium program before creating a new instance of ChromeDriver:
    System.setProperty("webdriver.chrome.driver","C:/Your/Path/to/chromedriver.exe");
    

That’s it. Problem should be solved. A whole working code sample could then look like this (again, first you need to edit the location of the chromedriver.exe):

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

/**
 * @author Nils Schuette via frontendtest.org
 */
public class ChromeDriverTest {

	/**
	 * @param args
	 * @throws InterruptedException
	 */
	public static void main(String
[] args) throws InterruptedException { // Telling the system where to find the chrome driver System.setProperty( "webdriver.chrome.driver", "C:/Your/Path/to/chromedriver.exe"); WebDriver webDriver = new ChromeDriver(); // Maximize the browser window webDriver.manage().window().maximize(); // Open google.com webDriver.navigate().to("http://www.google.com"); // Waiting a little bit before closing Thread.sleep(7000); // Closing the browser and webdriver webDriver.close(); webDriver.quit(); } }