Exception in thread quot;mainquot; java.lang.IllegalStateException:The path to the driver executable must be set by the : system property(线程“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"
- Escaping the back slash (
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 beforeWebDriver 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:驱动程序可执行文件的路径必须由:系统属性设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:线程“main"中的异常java.lang.IllegalStateException:驱动程序可执行文件的路径必须由:系统属性设置
基础教程推荐
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01