webdrivermanager icon indicating copy to clipboard operation
webdrivermanager copied to clipboard

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

Open dipan66 opened this issue 10 years ago • 15 comments

I have set up webdrivermanager as per instructions given in the readme. On running a test, the driver instantiation throws an error: 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$000(ChromeDriverService.java:32) 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 AccountQuery.start(AccountQuery.java:37) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142) at org.testng.TestRunner.beforeRun(TestRunner.java:656) at org.testng.TestRunner.run(TestRunner.java:624) at org.testng.SuiteRunner.runTest(SuiteRunner.java:366) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319) at org.testng.SuiteRunner.run(SuiteRunner.java:268) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244) at org.testng.TestNG.runSuitesLocally(TestNG.java:1169) at org.testng.TestNG.run(TestNG.java:1064) at Main.main(Main.java:16)

What am I doing wrong? Code snippet is given below:

public class AccountQuery {

    static WebDriver driver;
    private static final Logger log = Logger.getLogger("AccountQuery");
    private StringBuffer verificationErrors = new StringBuffer();

    @BeforeClass
    public static void setupClass() {
        ChromeDriverManager.getInstance().setup();
    }

    @BeforeTest
    public void start() {
        try{
            driver = new ChromeDriver();
        } catch (Exception ex){
            log.info("Exception while instantiating driver. ",ex);
        }
    }

    @Test(dataProvider="ConfigData",dataProviderClass=TestDataProvider.class)
    public void FirstLogin(Configuration config) throws InterruptedException {
        driver.manage().window().maximize();
        driver.get(config.getString("URL"));
        driver.findElement(By.id("username")).sendKeys(config.getString("username"));
        // other similar lines omitted
    }

    @AfterClass(alwaysRun = true)
    public void tearDown() throws Exception {
        if (driver != null) {
            driver.quit();
        }
    }
} 

Maven dependencies:

       <dependency>   
            <groupId>org.seleniumhq.selenium</groupId>   
            <artifactId>selenium-java</artifactId>   
            <version>2.53.0</version>   
        </dependency>   
        <dependency>   
            <groupId>org.seleniumhq.selenium</groupId>   
            <artifactId>selenium-chrome-driver</artifactId>   
            <version>2.53.0</version>   
        </dependency>   
        <dependency>   
            <groupId>io.github.bonigarcia</groupId>    
            <artifactId>webdrivermanager</artifactId>   
            <version>1.4.5</version>    
        </dependency>    

dipan66 avatar Jun 29 '16 15:06 dipan66

It seems the method with the annotation @BeforeClass is not being executed.

bonigarcia avatar Jun 29 '16 15:06 bonigarcia

It appears that testng annotations get invoked in a slightly different order - one that is confusing to many (including myself). It is:

    @BeforeSuite   
    @BeforeTest   
    @BeforeClass   
    @BeforeMethod   
    @Test   
    @AfterMethod   
    @AfterClass   
    @AfterTest   

Pushing ChromeDriverManager.getInstance().setup(); to @BeforeTest solved the issue. Thanks for a great utility 👍 👍 👍 !!

dipan66 avatar Jun 30 '16 01:06 dipan66

Hi I am having issues with my chrome driver. Below is the error:

Failed scenarios: C:/Users/Ampacattu/workspace/CucumberTel/src/cucumberFeatures/features.feature:3 # Scenario: To verify that the phones page is displayed

1 Scenarios (1 failed) 3 Steps (1 failed, 2 skipped) 0m0.475s

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:738) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:111) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:302) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:124) at cucumber.telf.TelfRunner.i_am_on_shop_home_page(TelfRunner.java:27) at ?.Given I am on shop home page(C:/Users/Ampacattu/workspace/CucumberTel/src/cucumberFeatures/features.feature:4)

The following is my runner file: package cucumber.telf;

import org.junit.runner.RunWith; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver;

import cucumber.api.CucumberOptions; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class) @CucumberOptions( plugin ={"pretty","json/target/"}, features={"src/cucumbertef/"} ) public class TelfRunner {

WebDriver driver = null;

@Given("^I am on shop home page$")
public void i_am_on_shop_home_page() throws Throwable {

	driver = new ChromeDriver();
	driver.navigate().to("https://www.o2.co.uk/");
	
	}

@When("^I click on phones$")
public void i_click_on_phones() throws Throwable {
  
	driver.findElement(By.id("pn1"));
}

@Then("^Phones listing page should be displayed$")
public void phones_listing_page_should_be_displayed() throws Throwable {
	
	driver.findElement(By.id("pn1")).click();
  
}

}

Please help

steffy1 avatar Feb 24 '17 15:02 steffy1

Add

 ChromeDriverManager.getInstance().setup();

in Given step def

Example,

@Given("^I am on shop home page$")
public void i_am_on_shop_home_page() throws Throwable {

       ChromeDriverManager.getInstance().setup();

	driver = new ChromeDriver();
	driver.navigate().to("https://www.o2.co.uk/");
	
	}

britka avatar Feb 24 '17 15:02 britka

@britka : I am getting an error for ChromeDriverManager.getInstance().setup();

Error: ChromeDriverManager cannot be resolved

steffy1 avatar Feb 24 '17 15:02 steffy1

@britka : I got it solved thought of sharing the solver : System.setProperty("webdriver.chrome.driver", "C:\Users\Ampacattu\Downloads\chromedriver_win32\chromedriver.exe");

steffy1 avatar Feb 24 '17 15:02 steffy1

@steffy1 If you manually set the System Property to provide chrome driver location path, what is the benefit of using this library. You can download the we drivers for all browsers and set the system property. Doesn't serve the purpose.

sagunpandey avatar Jun 02 '17 20:06 sagunpandey

Ihave similar error , i have set up all the required jar files and chrome location set up but still getting the error ....I am a beginner, please help me solve this issue .

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:124) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:33) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:139) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:335) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:89) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at chrome.main(chrome.java:11)

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

public class chrome {

public static void main(String[] args) 
{
	
	
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");
 WebDriver driver = new ChromeDriver();
 
 driver.get("www.gmail.com");
 
	       
     	}

}

1230priya avatar May 10 '18 07:05 1230priya

@1230priya - I have written using eclipse IDE. Add External JAR's without fail. Always worked for me both with Firefox and ChromeDriver. Try this. import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Example{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "D:\chromedriver_win32\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://google.com"); } }

sriranjani48 avatar Nov 21 '18 19:11 sriranjani48

Hi guys I am facing the same issue: Error:- 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$000(ChromeDriverService.java:32) 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.(ChromeDriver.java:116) at com.w2a.base.TestBase.setUp(TestBase.java:69) org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)

What I am doing wrong?? import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite;

public class TestBase {

public static WebDriver driver;
public static Properties config = new Properties();
public static Properties OR = new Properties();
public static FileInputStream fis;


@BeforeSuite
public void setUp()
{
	if (driver==null)
	{
		
		try {
			fis = new FileInputStream("C:\\Users\\bhupendra.nikam\\eclipse\\LearnAutomation\\LearnJava\\DataDrivenFramework\\src\\test\\resources\\properties\\Config.properties");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			config.load(fis);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		try {
			fis = new FileInputStream("C:\\Users\\bhupendra.nikam\\eclipse\\LearnAutomation\\LearnJava\\DataDrivenFramework\\src\\test\\resources\\properties\\OR.properties");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			OR.load(fis);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
if(config.getProperty("browser").equals("chrome"))
{
	System.getProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\src\\test\\resources\\executables\\chromedriver.exe");
	//System.setProperty("websriver.chrome.driver", "D:\\A Software\\Chrome13-08\\chromedriver.exe");
	driver = new ChromeDriver();
}
		
else if(config.getProperty("browser").equals("firefox"))
{
	System.getProperty("webdriver.gecko.driver", System.getProperty("user.dir")+"\\src\\test\\resources\\executables\\firefoxdriver.exe");
    driver = new FirefoxDriver();
}
		
	  driver.get(config.getProperty("testsiteurl"));
	  driver.manage().window().maximize();
	  driver.manage().timeouts().implicitlyWait(Integer.parseInt(config.getProperty("inplicit.wait")), TimeUnit.SECONDS);
		
		
}
	
	
}



@AfterSuite
public void tearDown()
{
	if(driver!=null)
	driver.quit();
}

}

BhupendraNikam01 avatar Feb 13 '19 06:02 BhupendraNikam01

Add External JAR's without fail and try this. package com.java_testing;

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

public class Test {

public static void main(String[] args) {
	System.setProperty("webdriver.chrome.driver", "C:\\Users\\subham\\Downloads\\selenium\\chrome_driver\\chromedriver.exe");
	WebDriver driver = new ChromeDriver();
	driver.get("https://google.com");
}

}

sksvns avatar Apr 23 '19 19:04 sksvns

HI , I am getting the below error: 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

Please find my code: import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver;

public class demo {

public static void main(String[] args) {
	// TODO Auto-generated method stub

WebDriver driver = new ChromeDriver(); System.setProperty("WebDriver.chrome.driver", "C:\Users\Abishek R\Downloads.exe"); driver.get("www.google.com"); System.out.println(driver.getTitle()); } }

Please help

Abishek-godsu avatar Sep 11 '19 03:09 Abishek-godsu

Hello, When I run the Test NG give me this error: FAILED CONFIGURATION: @BeforeTest OpenURL java.lang.IllegalStateException: The path to the driver executable 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 org.openqa.selenium.internal.Require$StateChecker.nonNull(Require.java:247) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:142) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:37) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:222) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:405) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:119) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:105) at FindingElements.FindElementByID.OpenURL(FindElementByID.java:18) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132) at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:61) at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:366) at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:320) at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:617) at org.testng.TestRunner.beforeRun(TestRunner.java:607) at org.testng.TestRunner.run(TestRunner.java:578) at org.testng.SuiteRunner.runTest(SuiteRunner.java:384) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337) at org.testng.SuiteRunner.run(SuiteRunner.java:286) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218) at org.testng.TestNG.runSuitesLocally(TestNG.java:1140) at org.testng.TestNG.runSuites(TestNG.java:1069) at org.testng.TestNG.run(TestNG.java:1037) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

ghost avatar Oct 06 '20 06:10 ghost

Hi All,

I am relatively new to selenium. I got the same issue as above and the problem was that I have created WebDriver object before setting SystemProperty. When I have written the code in the below order the problem solved. Hope it will be useful for someone. Thanks!

package SS;

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

public class SS { public static WebDriver driver = null; public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "C:/Users/haiso/eclipse-workspace2/SS/resources/chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.get("https://www.deepl.com/en/translator");
}
}

sindhuabraham avatar Feb 04 '21 13:02 sindhuabraham

Hi All,

We have been using the WebDriverManager for awhile now without any issues. For some reason after the latest version of Chrome 101.0.4951.41 installed, on one set of tests we are getting the error below:

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases

We have multiple test project setup the same way. Our GebConfig.Groovy is setup to setup the driver, as seen below:

'headless-chrome' { WebDriverManager.chromedriver().setup() driver = { ChromeOptions options = new ChromeOptions() options.addArguments('disable-infobars') options.setHeadless(true) options.addArguments('no-sandbox') options.addArguments('auth-server-whitelist=*rgare.net') options.addArguments('disable-popup-blocking') options.addArguments('window-size=1366,768') new ChromeDriver(options) } }

We've never had to specify the location of the driver, using System.setProperty, in the past, that is the point of using the manager. I can't seem to figure out what the difference is between this project and others that work that are setup the same way. Any suggestions on troubleshooting?

DarcheleWebb avatar May 04 '22 14:05 DarcheleWebb