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");
    }

}
2

5 Answers 5

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");
    
Sign up to request clarification or add additional context in comments.

1 Comment

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.
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.)

1 Comment

thanks, but this is a duplication answer to the answer above
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");

Comments

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");

Comments

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

1 Comment

Please surround the code in ``` characters to make it clearly formatted for stack overflow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.