java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;

时间:2016-07-02 06:01:23

标签: java google-chrome selenium selenium-webdriver

我想通过selenium + java打开chrome。但它显示了这些错误。

**** java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置; ****

 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 google.gmail1.<init>(gmail1.java:22)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
        at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

1 个答案:

答案 0 :(得分:3)

正如异常明确指出的那样,您必须提供chrome驱动程序可执行文件的路径。这可以在您的java代码System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver")中设置,也可以在命令行-Dwebdriver.chrome.driver=/path/to/chromedriver传递