java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property;

The path to the driver executable must be set by the webdriver.chrome.driverWhen people begin their work with Selenium they usually start with FirefoxDriver. When they try to switch to ChromeDriver they see exception in runtime, which says that you should specify the path to the driver executable in the system property called webdriver.chrome.driver.

Why do we see this IllegalStateException?

It is a big difference between WebDrivers for Firefox and Chrome. The first one can start browser window without any advanced preparation, the second one – does not. So all you need to do is to install Chrome WebDriver locally and set the webdriver.chrome.driver.

Installing Chrome WebDriver

To install chrome download it from official site and unzip into some folder. If you are using Linux you will need to put unzipped file into /usr/local/share and make it executable.

When it’s done we need to create system property. You can add it manually in your system settings or programmatically. We will show the last case.

Setting executable by the webdriver.chrome.driver system property in Java code

In this step you need to specify the webdriver.chrome.driver property using System.setProperty() method. There should be 2 arguments passed:

  • name of the system property
  • path to driver executable
System.setProperty("webdriver.chrome.driver", "<PATH_TO_SELENIUM>");

When you’ve done this, your ChromeDriver should work perfectly.

Leave a Reply

Be the First to Comment!