【发布时间】:2012-06-15 06:08:29
【问题描述】:
我正在使用 Selenium 来自动化测试。我的应用程序只使用 IE,它不能在其他浏览器上运行。
代码:
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 系统属性设置;有关详细信息,请参阅https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver。最新版本可从http://www.seleniumhq.org/download/下载 2012 年 6 月 12 日下午 4:18:42 org.apache.http.impl.client.DefaultRequestDirector tryExecute 信息:处理请求时捕获 I/O 异常 (java.net.SocketException):软件导致连接中止:recv 失败 2012 年 6 月 12 日下午 4:18:42 org.apache.http.impl.client.DefaultRequestDirector 尝试执行
有人可以帮我解决这个问题吗?
【问题讨论】:
-
不知道为什么我不能为此发布答案,但您也可以通过在相关机器上的 PATH Environment 值中指定文件夹位置来解决此问题。如果您希望或必须将文件存储在不同环境中不同机器上的不同位置,这很方便
-
替换行 System.setProperty("webdriver.chrome.driver","C:\\Users\\vthaduri\\workspace\\LDCSuite\\IEDriverServer.exe");通过 System.setProperty("webdriver.ie.driver","C:\\Users\\vthaduri\\workspace\\LDCSuite\\IEDriverServer.exe");
-
您已经为 chrome 而不是 IE 设置了属性。这只是问题
标签: java internet-explorer selenium-webdriver webdriver system-properties