问题描述
我正在使用Selenium来自动化测试。我的应用程序专门使用IE浏览器,它不适用于其他浏览器。
I am using Selenium for automating the tests. My application exclusively uses IE, it will not work on other Browsers.
代码:
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class Test {
public static void main(String[] args) {
final String sUrl = "http://www.google.co.in/";
System.setProperty("webdriver.chrome.driver","C:\\Users\\vthaduri\\workspace\\LDCSuite\\IEDriverServer.exe");
WebDriver oWebDriver = new InternetExplorerDriver();
oWebDriver.get(sUrl);
WebElement oSearchInputElem = oWebDriver.findElement(By.name("q")); // Use name locator to identify the search input field.
oSearchInputElem.sendKeys("Selenium 2");
WebElement oGoogleSearchBtn = oWebDriver.findElement(By.xpath("//input[@name='btnG']"));
oGoogleSearchBtn.click();
try {
Thread.sleep(5000);
} catch(InterruptedException ex) {
System.out.println(ex.getMessage());
}
oWebDriver.close();
}
}
这是我得到的错误
驱动程序可执行文件的路径必须由webdriver.ie.driver系统属性设置;有关详细信息,请参阅。最新版本可以从下载
2012年6月12日4:18:42 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO:处理请求时捕获的I / O异常(java.net.SocketException):软件导致连接中止:recv failed
2012年6月12日下午4:18:42 org.apache.http.impl.client.DefaultRequestDirector tryExecute
The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://www.seleniumhq.org/download/Jun 12, 2012 4:18:42 PM org.apache.http.impl.client.DefaultRequestDirector tryExecuteINFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failedJun 12, 2012 4:18:42 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
有人可以帮我吗?
推荐答案
-
您的系统上需要InternetExplorer驱动程序可执行文件。所以从暗示来源()下载解压缩它放在你能找到的地方。在我的示例中,我假设您将其放置在
C:\ Selenium \ xxxldieder.exe
You will need InternetExplorer driver executable on your system. So download it from the hinted source (http://www.seleniumhq.org/download/) unpack it and place somewhere you can find it. In my example, I will assume you will place it to
C:\Selenium\iexploredriver.exe
然后你必须在系统中进行设置。这是从我的Selenium项目粘贴的Java代码:
Then you have to set it up in the system. Here is the Java code pasted from my Selenium project:
File file = new File("C:/Selenium/iexploredriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
基本上,您必须设置此属性在之前初始化驱动程序
Basically, you have to set this property before you initialize driver
这篇关于必须通过webdriver.ie.driver系统属性设置驱动程序可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!