线程“main"中的异常java.lang.IllegalStateException:驱动程序可执行文件的路径必须由:系统属性设置 [英] Exception in thread "main" java.lang.IllegalStateException:The path to the driver executable must be set by the : system property

查看:23
本文介绍了线程“main"中的异常java.lang.IllegalStateException:驱动程序可执行文件的路径必须由:系统属性设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

线程main"中的异常 java.lang.IllegalStateException :驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置;有关详细信息,请参阅 https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.最新版本可从 http://chromedriver.storage.googleapis.com/index.html 下载在 com.google.common.base.Preconditions.checkState(Preconditions.java:199)在 org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)在 org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)在 org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) 在 org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)在 org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) 在 org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)在 practice_locators.DatePicker.main(DatePicker.java:11)

这是我的代码:

包practice_locators;导入 org.openqa.selenium.WebDriver;导入 org.openqa.selenium.chrome.ChromeDriver;公共类 DatePicker {公共静态无效主要(字符串[]参数){WebDriver driver = new ChromeDriver();System.setProperty("WebDriver.Chrome.driver", "E:\chromedriver.exe");driver.get("https://www.google.com");}}

解决方案

错误说明了一切:

线程main"中的异常 java.lang.IllegalStateException :驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置;有关详细信息,请参阅 https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.最新版本可从 http://chromedriver.storage.googleapis.com/index.html 下载在 com.google.common.base.Preconditions.checkState(Preconditions.java:199)

错误中的以下短语暗示包含 webdriver.chrome.driver

的行中存在错误

错误可能是以下任何一种:

  • 系统类方法 setProperty()(包括序列):

    System.setProperty()

    <块引用>

    这一行应该是您脚本中的第一行.

  • 指定的 :

    "WebDriver.Chrome.driver"

  • 字段出错:

    "E:\chromedriver.exe"

    <块引用>

    您必须通过以下任一选项传递 WebDriver 的绝对路径:

    • 转义反斜杠 (\) 例如"C:\path\to\chromedriver.exe"
    • 单正斜杠 (/) 例如"C:/path/to/chromedriver.exe"

您的代码似乎有如下两个问题:

  • 第一个问题是指定 Key 而不是 "WebDriver.Chrome.driver" 应该是 "webdriver.chrome.driver"如下:

    System.setProperty("webdriver.chrome.driver", "E:\chromedriver.exe");

  • 第二个问题是在 序列 提到 Key "webDriver.chrome.driver" 在你的程序中应该在 WebDriver driver = new ChromeDriver(); 之前如下:

    System.setProperty("WebDriver.Chrome.driver", "E:\chromedriver.exe");WebDriver driver = new ChromeDriver();driver.get("https://www.google.com");

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$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 practise_locators.DatePicker.main(DatePicker.java:11)

Here is my code:

package practise_locators;

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

public class DatePicker {

    public static void main(String[] args){
        WebDriver driver = new ChromeDriver();
        System.setProperty("WebDriver.Chrome.driver", "E:\chromedriver.exe");
        driver.get("https://www.google.com");
    }

}

解决方案

The error says it all :

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) 

The following phrases from the error implies that there is an error in the line containing webdriver.chrome.driver

The error can be either of the following :

  • Error in the System Class Method setProperty()(including sequence) :

    System.setProperty()
    

    This line should be the very first line in your script.

  • Error in the specified Key :

    "WebDriver.Chrome.driver"
    

  • Error in the Value field :

    "E:\chromedriver.exe"
    

    You have to pass the absolute path of the WebDriver through either of the following options :

    • Escaping the back slash (\) e.g. "C:\path\to\chromedriver.exe"
    • Single forward slash (/) e.g. "C:/path/to/chromedriver.exe"

Your code seems to be having two issues as follows :

  • First issue is in specifying the Key which instead of "WebDriver.Chrome.driver" should have been "webdriver.chrome.driver" as follows :

    System.setProperty("webdriver.chrome.driver", "E:\chromedriver.exe");
    

  • Second issue is in the sequence of mentioning the Key "webDriver.chrome.driver" in your program which should be before WebDriver driver = new ChromeDriver(); as follows :

    System.setProperty("WebDriver.Chrome.driver", "E:\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.google.com");
    

这篇关于线程“main"中的异常java.lang.IllegalStateException:驱动程序可执行文件的路径必须由:系统属性设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆