eclipse 无法从 Selenium Webdriver 启动 IE/Chrome
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22017678/
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
Not able to launch IE/Chrome from Selenium Webdriver
提问by Shubham Jaiswal
While launching IE from Selenium Webdriver following error is shown:
从 Selenium Webdriver 启动 IE 时显示以下错误:
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property. at com.google.common.base.Preconditions.checkState(Preconditions.java:177) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105) at org.openqa.selenium.ie.InternetExplorerDriverService.access$1(InternetExplorerDriverService.java:1) at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.build(InternetExplorerDriverService.java:230) at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:263) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:182) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:155)
线程“main”中的异常 java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.ie.driver 系统属性设置。在 com.google.common.base.Preconditions.checkState(Preconditions.java:177) 在 org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105) 在 org.openqa.selenium.ie.InternetExplorerDriverService .access$1(InternetExplorerDriverService.java:1) 在 org.openqa.selenium.ie.InternetExplorerDriverService$Builder.build(InternetExplorerDriverService.java:230) 在 org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:263)在 org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:182) 在 org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:155)
Code used :
使用的代码:
public class Browser {
public static void main(String[] args) {
WebDriver obj = new InternetExplorerDriver();
System.getProperty("webdriver.ie.driver", "D:\Eclipse Workspace\Multi Browser\IEDriverServer.exe");
obj.get("http://www.google.com/");
obj.close();
}
回答by Faiz
InternetExplorerDriver
object should be created afterthe webdriver.ie.driver
property is set. Similarly for chrome.
InternetExplorerDriver
要创建的对象后的webdriver.ie.driver
属性设置。铬也是如此。
Also, the referenced code uses getProperty()
, whereas you need to use setProperty()
to actually set it.
此外,引用的代码使用getProperty()
,而您需要使用setProperty()
来实际设置它。
System.setProperty("webdriver.ie.driver", "D:\Eclipse Workspace\Multi Browser\IEDriverServer.exe");
WebDriver obj = new InternetExplorerDriver();
obj.get("http://www.google.com/");
obj.close();
回答by Sathish D
You have to use setProperty()
function. Basically, you have to set this property before you initialize driver. But you are using getProperty()
.
你必须使用setProperty()
函数。基本上,您必须在初始化驱动程序之前设置此属性。但是您正在使用getProperty()
.
Here is the sample Java code:
这是示例 Java 代码:
public class IE {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.ie.driver", "D:\SATHISH\SOFTWARES\SELENIUM\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("www.google.com");
driver.findElement(By.id("gbqfq")).sendKeys("abc");
driver.close();
}
}