balvinder dhillon balvinder dhillon - 3 months ago 15
Java Question

Getting java.lang.IllegalStateException even after adding set property webdriver

I am getting 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 https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.
The latest version can be downloaded from
http://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
at SeleniumFirefox.main(SeleniumFirefox.java:11)


Below is the code used SeleniumFirefox.java:

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

public class SeleniumFirefox {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chromedriver.driver",
"C://Users//balwinder//Desktop//chromedriver.exe");
WebDriver driver = new ChromeDriver();

/*try {
Thread.sleep(5000);
} catch(InterruptedException ex) {
System.out.println(ex.getMessage());
}*/

}}

Answer

set webdriver.chrome.driver instead of webdriver.chromedriver.driver

 System.setProperty("webdriver.chromedriver.driver",
           "C://Users//balwinder//Desktop//chromedriver.exe");

Should be:

System.setProperty("webdriver.chrome.driver",
           "C:\\Users\\balwinder\\Desktop\\chromedriver.exe");

OR

System.setProperty("webdriver.chrome.driver",
           "C:/Users/balwinder/Desktop/chromedriver.exe");