2
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 practise_locators.DatePicker.main(DatePicker.java:11)

Here is my code:

package practise_locators;

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

public class DatePicker {

    public static void main(String[] args){
        WebDriver driver = new ChromeDriver();
        System.setProperty("WebDriver.Chrome.driver", "E:\\chromedriver.exe");
        driver.get("https://www.google.com");
    }

}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Prashant Morade
  • 31
  • 1
  • 1
  • 7
  • Possible duplicate of [Getting "The path to the driver executable must be set by the webdriver.chrome.driver system property"though set correct path](https://stackoverflow.com/questions/44476647/getting-the-path-to-the-driver-executable-must-be-set-by-the-webdriver-chrome-d) – JeffC Mar 18 '18 at 17:26
  • A quick google of the error message would have brought up info that would have solved your problem. – JeffC Mar 18 '18 at 17:26

5 Answers5

5

The error says it all :

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) 

The following phrases from the error implies that there is an error in the line containing webdriver.chrome.driver

The error can be either of the following :

  • Error in the System Class Method setProperty()(including sequence) :

    System.setProperty()
    

    This line should be the very first line in your script.

  • Error in the specified Key :

    "WebDriver.Chrome.driver"
    
  • Error in the Value field :

    "E:\\chromedriver.exe"
    

    You have to pass the absolute path of the WebDriver through either of the following options :

    • Escaping the back slash (\\) e.g. "C:\\path\\to\\chromedriver.exe"
    • Single forward slash (/) e.g. "C:/path/to/chromedriver.exe"

Your code seems to be having two issues as follows :

  • First issue is in specifying the Key which instead of "WebDriver.Chrome.driver" should have been "webdriver.chrome.driver" as follows :

    System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");
    
  • Second issue is in the sequence of mentioning the Key "webDriver.chrome.driver" in your program which should be before WebDriver driver = new ChromeDriver(); as follows :

    System.setProperty("WebDriver.Chrome.driver", "E:\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.google.com");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I agree that it is all about the provided PATH of the driver. Mac and Windows work differently, so you must check the / and \ as well as the folder structure. – Yasin Bekar Sep 20 '22 at 21:14
1

Download the chromedriver version corresponding to the chrome version in your system from https://chromedriver.chromium.org/downloads . Unzip the file and run the below code in the IDE.

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

public class Selintroduction {

public static void main(String[] args) {

    //Invoking browser
System.setProperty("webdriver.chrome.driver","C:\\Users\\HP\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

}

}

(Path would depend on your file location in the PC.)

Vanshika
  • 11
  • 1
0

I have seen many people are using wrong sequence. the sequence should be.

  1. First set the property and then launch the browser

System.setProperty("webdriver.chrome.driver", "F:/chrome/chromedriver.exe"); WebDriver driver = new ChromeDriver();

      driver.navigate().to("https://www.google.com");
0

I was facing the same error when my code was like so:

System.setProperty("webdriver.chrome.driver","C:\\Users\\abs\\chromedriver_win32.exe");

It works after adding "chromedriver" before ".exe" like so:

System.setProperty("webdriver.chrome.driver","C:\\Users\\abs\\chromedriver_win32\\chromedriver.exe");
flyingfishcattle
  • 1,817
  • 3
  • 14
  • 25
arjun
  • 31
  • 2
  • 5
0

try to use WebDriverManager.chromedriver().setup(); WebDriver driver = new ChromeDriver();

if the path is not working, please use latest selenium webdriver like 4.10 and use above code

meen
  • 1
  • 1