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

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>    

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (1 by maintainers)

Most upvoted comments

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

@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”); } }

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

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?

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

}

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

Error: ChromeDriverManager cannot be resolved

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 👍 👍 👍 !!