异常 (org.openqa.selenium.NoSuchWindowException):在 Internet Explorer 中使用 Selenium WebDriver 和 Java
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16557986/
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
Exception (org.openqa.selenium.NoSuchWindowException): using Selenium WebDriver with Java in Internet Explorer
提问by Amit
While using IE for automation using Selenium Webdriver, I am able to open the URL but finding the element on that page is throwing the following exception:
在使用 IE 使用 Selenium Webdriver 进行自动化时,我能够打开 URL,但在该页面上找到该元素会引发以下异常:
org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)
org.openqa.selenium.NoSuchWindowException:无法在关闭的窗口上找到元素(警告:服务器没有提供任何堆栈跟踪信息)
I have tried the driver.switchTo.window()
method but it's not working.
I have searched it for hours and I am not getting anywhere.
我已经尝试了该driver.switchTo.window()
方法,但它不起作用。我已经搜索了几个小时,但一无所获。
Here's the code:
这是代码:
public static Selenium selenium;
public static void main(String args[]) {
try {
System.setProperty(
"webdriver.ie.driver",
"D:\Driver\IEDriverServer_Win32_2.32.3_latest\IEDriverServer.exe");
DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
capab.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
WebDriver driver = new InternetExplorerDriver(capab);
driver.get("http://www.google.com");
driver.findElement(By.xpath(".//*[@id='addlang']/a[1]")).click();
} catch (Exception e) {
e.printStackTrace();
}
}
采纳答案by Yi Zeng
Remove capability INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
and manually set your IE protected mode settings to be the same for all zones.
删除功能INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
并将您的 IE 保护模式设置手动设置为所有区域都相同。
Source:
来源:
回答by Venkatesh Chinna
case "ie_driver":
//IE CODE
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "https://testvmm6.partnersonline.com/vmm");
cap.internetExplorer().setCapability("ignoreProtectedModeSettings", true);
System.setProperty("webdriver.ie.driver", System.getProperty("user.dir")+"//exe//IEDriverServer1.exe");
cap.setCapability("IE.binary", "C:/Program Files (x86)/Internet Explorer/iexplore.exe");
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setJavascriptEnabled(true);
cap.setCapability("requireWindowFocus", true);
cap.setCapability("enablePersistentHover", false);
回答by Diana S.
The issue that helped me was to set init page (IE 11 both 32 and 64)
帮助我的问题是设置初始化页面(IE 11 32 和 64)
private WebDriver getIEDriver() {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, INIT_PAGE);
File file = new File("E:/drivers/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
return new InternetExplorerDriver(cap);
}
回答by user3518765
The best bet here is to make some tweaks to the registry:
最好的办法是对注册表进行一些调整:
Go to registry edit (
regedit
from windows run)Look in your registry under the
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Zones
. Over there, you should see keys number 0-4 . Under these keys 0-4, look for a value named 2500For all the keys from 0-4, have the same data for value 2500. For example, for key 0 if the value 2500 has data as 3 (hex data), then make the data for value 2500 as 3 for all the other keys (1,2,3,4).
Now try to run the script.
转到注册表编辑(
regedit
从 Windows 运行)在
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Zones
. 在那里,您应该会看到编号为 0-4 的键。在这些键 0-4 下,查找名为 2500 的值对于 0-4 的所有键,值 2500 的数据相同。例如,对于键 0,如果值 2500 的数据为 3(十六进制数据),则将所有其他键的值 2500 的数据设为 3 (1,2,3,4)。
现在尝试运行脚本。