我想在IE中打开一个google网页(google.com),但在运行我的脚本时显示“org.openqa.selenium.NoSuchWindowException:无法获取浏览器(警告:服务器未提供任何堆栈跟踪信息)显示正在运行“错误。 我正在使用IE: - 11 窗户: - 8.1; 64位。
我的代码是: -
System.setProperty("Webdriver.ie.driver", "C:\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("https://google.co.in");
// driver.get("javascript:document.getElementById('overridelink').click();");
System.out.println(driver.getCurrentUrl());
Thread.sleep(3000);
System.out.println(driver.getCurrentUrl());
String PageTitle = driver.getTitle();
Thread.sleep(3000);
if (PageTitle.equals("Google")){
System.out.println("test case passed");
}
else {
System.out.println("failed");
}
答案 0 :(得分:0)
尝试以下代码:这在我的最后工作正常
System.setProperty("webdriver.ie.driver", "D:\\IEDriverServer.exe");
DesiredCapabilities cappabilities = DesiredCapabilities.internetExplorer();
cappabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
cappabilities.setCapability("platform", "WIN8");
cappabilities.setCapability("version", "11");
cappabilities.setCapability("browserName", "internet explorer");
cappabilities.setCapability("ignoreProtectedModeSettings",1);
cappabilities.setCapability("nativeEvents","false");
cappabilities.setCapability("requireWindowFocus","true");
WebDriver driver = new InternetExplorerDriver(cappabilities);
driver.manage().window().maximize();
driver.get("https://google.co.in");
System.out.println(driver.getCurrentUrl());
Thread.sleep(3000);
System.out.println(driver.getCurrentUrl());
String PageTitle = driver.getTitle();
Thread.sleep(3000);
if (PageTitle.equals("Google")){
System.out.println("test case passed");
}
else {
System.out.println("failed");
}
如果这是在你的最后工作,请告诉我
答案 1 :(得分:0)
首先在IE浏览器中设置保护模式设置。请按照以下步骤操作:
在Selenium脚本中使用以下功能:
System.setProperty("webdriver.ie.driver","C:\\IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURIY_DOMAINS, true);
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capabilities.setCapability("allow-blocked-content", true);
WebDriver driver = new InternetExplorerDriver(capabilities);
再次运行Selenium脚本。这次它将起作用。