[英]Exception (org.openqa.selenium.NoSuchWindowException): using Selenium WebDriver with Java in Internet Explorer
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. 我尝试过driver.switchTo.window()
方法,但它无法正常工作。 I have searched it for hours and I am not getting anywhere. 我已经搜索了几个小时,我没有到达任何地方。
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();
}
}
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: 资源:
http://jimevansmusic.blogspot.com/2012/08/youre-doing-it-wrong-protected-mode-and.html http://jimevansmusic.blogspot.com/2012/08/youre-doing-it-wrong-protected-mode-and.html
NoSuchElementException is occurred during implementation of InternetExplorerDriver in Selenium WebDriver 在Selenium WebDriver中实现InternetExplorerDriver期间发生NoSuchElementException
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);
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);
}
The best bet here is to make some tweaks to the registry: 这里最好的选择是对注册表进行一些调整:
Go to registry edit ( regedit
from windows run) 转到注册表编辑(从Windows运行regedit
)
Look in your registry under the HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\InternetSettings\\Zones
. 在HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\InternetSettings\\Zones
下的注册表中查找。 Over there, you should see keys number 0-4 . 在那里,你应该看到键号0-4。 Under these keys 0-4, look for a value named 2500 在这些键0-4下,查找名为2500的值
For 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). 对于0-4中的所有键,对于值2500具有相同的数据。例如,对于键0,如果值2500具有数据3(十六进制数据),则对于所有其他键,将值2500的数据设为3 (1,2,3,4)。
Now try to run the script. 现在尝试运行脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.