java.lang.IllegalStateException Error after adding set property webdriver

0 votes

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 my code

 import org.openqa.selenium.WebDriver;

 import org.openqa.selenium.chrome.ChromeDriver;

 org.openqa.selenium.WebDriver;

 import org.openqa.selenium.WebElement;


 public class TestDemo {


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

}*/

   }}
Apr 19, 2018 in Selenium by Martin
• 4,320 points
4,888 views

3 answers to this question.

0 votes

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

NOTE: it will work only if you are first setting the system property and then instantiating chrome driver.

answered Apr 19, 2018 by Vardy
• 2,370 points
This really helped. Thanks!
It worked for my whole class.
0 votes
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

public class Demo2 {

       public static void main(String[] args) {

              // TODO Auto-generated method stub

              System.setProperty("webdriver.chrome.driver", "I:\\Bhasker-ShiroCode\\work\\chromedriver.exe");

              WebDriver driver = new ChromeDriver();

              driver.get("http://google.com");

       }

}

To avoid Error

webdriver.chrome.driver  ( should be in small letters )

have to give correct chromedriver.exe ( correct path )

Import all Selenium jars under class Path

answered Apr 15, 2019 by Bhasker vade

edited Apr 16, 2019 by Omkar
which jar files need to be associated?

@Mina, you need to import all the Selenium Standalone Server (latest version) and Selenium Server (latest version) Jar files into your project. You can download these files with any version of your choice from here: http://selenium-release.storage.googleapis.com/index.html

0 votes
/*

System.setProperty("WebDriver.gecko.driver", "C:\\Users\\DELL\\Desktop\\GeckoDriver1\\geckodriver.exe");

WebDriver driver = new FirefoxDriver();

*/

    System.setProperty("WebDriver.Chrome.Driver", "C:\\Users\\DELL\\Desktop\\Chrome Driver\\chromedriver_win32.exe");

    WebDriver Driver= new ChromeDriver();

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:847)

at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)

at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)

at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)

at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)

at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)

at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)

at Seleniumpracticesessions.SeleniumWebdriverBasics.main(SeleniumWebdriverBasics.java:17)

I am trying to launch Mozilla FF/Chrome browser, however not able to launch the any of the specified browsers, above mentioned Exceptions are displayed, any one can help me..

answered May 1, 2019 by anonymous

Hi, your code is throwing these exceptions because you are setting the system property in a wrong manner, instead of using "WebDriver.Chrome.Driver", use "webdriver.chrome.driver" in System.setProperty() function. As, you should know that Java is a case-sensitive language, so if you set system properties in capital-case, system won't recognize the property and hence, will throw an exception. 

Similarly, for firefox driver, use "webdriver.gecko.driver" as system property.

Related Questions In Selenium

0 votes
1 answer

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

Hi Sivaranjani, to resolve your issue, Driver path ...READ MORE

answered Sep 3, 2019 in Selenium by Abha
• 27,720 points
652 views
0 votes
1 answer

Java.lang.CharSequence cannot be resolved error while using sendKeys() using Selenium Webdriver

You could try this, myElement .sendKeys(new String[] { ...READ MORE

answered Apr 4, 2018 in Selenium by Johnathon
• 9,090 points
857 views
0 votes
0 answers
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,510 points
1,485 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,850 points
1,462 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,850 points
1,223 views
+9 votes
15 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,370 points
83,568 views
0 votes
1 answer

Select an item from a dropdown list using Selenium WebDriver

Use this then it will work - new ...READ MORE

answered Apr 9, 2018 in Selenium by Vardy
• 2,370 points
3,066 views