线程“main”java.lang.IllegalStateException 中的异常:驱动程序可执行文件的路径必须由:系统属性设置
Posted
技术标签:
【中文标题】线程“main”java.lang.IllegalStateException 中的异常:驱动程序可执行文件的路径必须由:系统属性设置【英文标题】:Exception in thread "main" java.lang.IllegalStateException:The path to the driver executable must be set by the : system property 【发布时间】:2018-08-27 06:04:32 【问题描述】: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)
这是我的代码:
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");
【问题讨论】:
Getting "The path to the driver executable must be set by the webdriver.chrome.driver system property"though set correct path的可能重复 对错误消息的快速谷歌会提出可以解决您的问题的信息。 【参考方案1】:错误说明了一切:
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)
错误中的以下短语暗示包含 webdriver.chrome.driver
的行中存在错误错误可能是以下任何一种:
System Class MethodsetProperty()
(包括序列)中的错误:
System.setProperty()
这一行应该是您脚本中的第一行。
在指定的Key 中出错:
"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");
第二个问题是序列在你的程序中提到键 "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");
【讨论】:
以上是关于线程“main”java.lang.IllegalStateException 中的异常:驱动程序可执行文件的路径必须由:系统属性设置的主要内容,如果未能解决你的问题,请参考以下文章
线程“main”中的异常 java.lang.ClassNotFoundException: sample.Main - 为啥?