简体   繁体   中英

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

I have made the Java Selenium Maven Project for printing all the data of the rows as well as header.The code worked fine but when i used the project on different system then i got the following error:-

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

I don't think that i need to set path for the jar in the maven project. Where i am missing ?

Note:- The code worked fine in the other system. The problem is not only with this code , approximately all the Selenium Maven project which i imported from other system is not working.

More Info:- There is no error in properties->java build path

 package com.xxx.webTableTest; import java.util.List; import org.apache.log4j.Logger; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class WebTableTest { WebDriver driver; Logger logger; @BeforeTest public void setUp() { logger = Logger.getLogger(WebTableTest.class); driver = new ChromeDriver(); driver.get("http://www.seleniumeasy.com/test/table-pagination-demo.html"); logger.info("navigated to the test website for the webtable"); } @Test public void testRadioButton() { List<WebElement> header = driver.findElements(By.tagName("th")); logger.info("Printing all the table headers"); for (WebElement webElement : header) { System.out.println(webElement.getText()); } List<WebElement> rows = driver.findElements(By.tagName("tr")); logger.info("Printing all the table rows"); for (WebElement webElement : rows) { System.out.println(webElement.getText()); } } @AfterTest public void tearDown() { driver.quit(); } } ------------------------------- POM.xml file -------------------------------- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>Sapient</groupId> <artifactId>page-object-model-v2</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-api</artifactId> <version>3.10.0</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-chrome-driver</artifactId> <version>3.10.0</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-firefox-driver</artifactId> <version>3.10.0</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>htmlunit-driver</artifactId> <version>2.29.0</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> </project> ----------------- TestNG Run result ----------------- [RemoteTestNG] detected TestNG version 6.14.2 FAILED CONFIGURATION: @BeforeTest setUp 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:32) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123) at com.sapient.webTableTest.WebTableTest.setUp(WebTableTest.java:23) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:455) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142) at org.testng.TestRunner.beforeRun(TestRunner.java:529) at org.testng.TestRunner.run(TestRunner.java:497) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) SKIPPED CONFIGURATION: @AfterTest tearDown SKIPPED: testRadioButton 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:32) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123) at com.sapient.webTableTest.WebTableTest.setUp(WebTableTest.java:23) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:455) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142) at org.testng.TestRunner.beforeRun(TestRunner.java:529) at org.testng.TestRunner.run(TestRunner.java:497) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) =============================================== Default test Tests run: 1, Failures: 0, Skips: 1 Configuration Failures: 1, Skips: 1 =============================================== =============================================== Default suite Total tests run: 1, Failures: 0, Skips: 1 Configuration Failures: 1, Skips: 1 ===============================================

strong text

You have to set path to your chromedriver.exe file.

Something like:

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

Or you can set location of your chromedriver.exe file in your path in system environments. But in both cases you need to have chromedriver.exe file stored somewhere on your system.

EDIT: Since it works on your work machine you probably have folder which contains your .exe file added in your system environment path variable. Compare those two variables (your home and work machine) to be sure.

Check this for more details.

  1. Download chrome driver
  2. make a driver folder alongside your project folder
  3. placed chrome driver in driver folder
  4. Add this code in your setup method

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; TestNG Selenium Java — java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; (driver.get) Error :"java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property" is displayed java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property-The Similiar doesn't ans Selenium grid with Chrome driver (WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property) Selenium Java - java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property The path to the driver executable must be set by the webdriver.chrome.driver; IllegalStateException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM