【发布时间】:2017-09-09 05:16:51
【问题描述】:
尝试使用 IE 驱动程序在 Luna Eclipse 中运行脚本 并得到以下错误:
线程“主”org.openqa.selenium.remote.UnreachableBrowserException 中的异常:无法启动新会话。可能的原因是远程服务器地址无效或浏览器启动失败。这是尝试运行的代码:
package com.newpack;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SecondClass {
public static void main(String[] args)
{
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability("requireWindowFocus", true);
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL,"https://www.google.co.in");
System.setProperty("webdriver.ie.driver","M:\\workspace\\IEDriver.exe");
WebDriver driver ;
driver = new InternetExplorerDriver(capabilities);
String baseUrl = "https://www.google.co.in";
driver.get(baseUrl);
String expectedTitle = "Google";
String actualTitle = "";
actualTitle = driver.getTitle();
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
driver.close();
System.exit(0);
}
}
【问题讨论】:
-
您的代码对我来说运行良好。请交叉检查您是否使用了正确的驱动程序。如果您的机器是 32 位的,那么您应该只使用 32 位的 IE 驱动程序。