即使在添加 set 属性 webdriver 后仍获取 java.lang.IllegalStateException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37404446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting java.lang.IllegalStateException even after adding set property webdriver
提问by balvinder dhillon
I am getting 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 import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class SeleniumFirefox {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chromedriver.driver",
"C://Users//balwinder//Desktop//chromedriver.exe");
WebDriver driver = new ChromeDriver();
/*try {
Thread.sleep(5000);
} catch(InterruptedException ex) {
System.out.println(ex.getMessage());
}*/
}}
(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 SeleniumFirefox.main(SeleniumFirefox.java:11)
Below is the code used SeleniumFirefox.java:
下面是使用SeleniumFirefox.java的代码:
System.setProperty("webdriver.chromedriver.driver",
"C://Users//balwinder//Desktop//chromedriver.exe");
采纳答案by user861594
set webdriver.chrome.driver
instead of webdriver.chromedriver.driver
设置webdriver.chrome.driver
而不是webdriver.chromedriver.driver
System.setProperty("webdriver.chrome.driver",
"C:\Users\balwinder\Desktop\chromedriver.exe");
Should be:
应该:
System.setProperty("webdriver.chrome.driver",
"C:/Users/balwinder/Desktop/chromedriver.exe");
OR
或者
##代码##NOTE: it will work only if you are first setting the system property and then instantiating chrome driver..
注意:只有当您首先设置系统属性然后实例化 chrome 驱动程序时,它才会起作用。
回答by Alexander P.
Another solution without System.setProperty
is simply add folder with chromedriver.exe
to PATH
(if someone don't know how - google "set path variable").
另一个没有的解决方案System.setProperty
是简单地将文件夹添加chromedriver.exe
到 PATH (如果有人不知道如何 - 谷歌“设置路径变量”)。
To check that this approach works you may put chromedriver.exe
to C:\Windows\System32
folder.
要检查,这种方法工作你可以将chromedriver.exe
到C:\Windows\System32
文件夹中。