必须通过webdriver.chrome.driver系统属性设置驱动程序可执行文件的路径;

时间:2017-06-05 08:53:19

标签: java selenium

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$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:120)

1 个答案:

答案 0 :(得分:1)

以下是您的问题的答案:

当您使用Selenium 3.x时,您必须从here下载 chromedriver.exe 并将其保存在您的计算机中。接下来,您必须提到 chromedriver.exe System.setProperty的绝对路径。当你提到 chromedriver.exe System.setProperty的绝对路径时,你要么提供前斜杠“ / ”,要么反过来“ \ \ \ ”。这是你自己的工作代码,有一些简单的调整:

public class first 
{
    public static void main(String args[])
    {
        System.setProperty("webdriver.chrome.driver","C:/your_directory/chromedriver.exe");
        WebDriver dr1= new ChromeDriver(); ;
        dr1.get("http://www.google.com/");
    }
}

请告诉我这是否是您的问题