本文介绍了甚至在添加set属性webdriver后获取java.lang.IllegalStateException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在线程mainjava.lang.IllegalStateException中获得异常:
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$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 SeleniumFirefox.main(SeleniumFirefox.java:11)
以下是使用的代码 SeleniumFirefox.java :
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());
}*/
}}
推荐答案
设置 webdriver.chrome.driver
而不是 webdriver.chromedriver.driver
System.setProperty("webdriver.chromedriver.driver",
"C://Users//balwinder//Desktop//chromedriver.exe");
应该是:
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\balwinder\\Desktop\\chromedriver.exe");
OR
System.setProperty("webdriver.chrome.driver",
"C:/Users/balwinder/Desktop/chromedriver.exe");
注意:仅在首次设置系统属性时才有效然后实例化chrome driver ..
NOTE: it will work only if you are first setting the system property and then instantiating chrome driver..
这篇关于甚至在添加set属性webdriver后获取java.lang.IllegalStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!