首页 > 解决方案 > 使用 Selenium 的 Internet Explorer 驱动程序在访问外部网页时不允许处理窗口

问题描述

当我访问http://localhost中的页面时... Selenium 允许我管理窗口,例如更改其位置,但是当我从另一台服务器访问页面时,我收到以下错误:

org.openqa.selenium.NoSuchWindowException: 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 处的 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 处检索当前窗口时出错。 java:45) 在 java.lang.reflect.Constructor.newInstance(Constructor.java:423) 在 org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187) 在 org.openqa.selenium.remote .http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122) 在 org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) 在 org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java :158) 在 org.openqa。selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) 在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) 在 org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow。 setPosition(RemoteWebDriver.java:807) 在 seleniumie.SeleniumIE.main(SeleniumIE.java:49)

我的代码:

Point esconder = new Point(-1000,-1000);
String URL = "http://www.google.com/";
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability("nativeEvents", false);
cap.setCapability("unexpectedAlertBehaviour", "accept");
cap.setCapability("ignoreProtectedModeSettings", true);
cap.setCapability("disable-popup-blocking", true);
cap.setCapability("enablePersistentHover", true);
cap.setCapability("ignoreZoomSetting", true);
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
InternetExplorerOptions options = new InternetExplorerOptions();
options.merge(cap);
visor = new InternetExplorerDriver(options);
visor.get(URL);
Thread.sleep(3000);
visor.manage().window().setPosition(esconder);

当我运行最后一行时,我得到了错误

我用的是IE11浏览器

标签: seleniumselenium-webdriverinternet-explorer-11

解决方案


我找到了解决方案!

出现问题是因为 Internet Explorer 已启用保护模式,当我禁用保护模式时,它对我来说非常有效。


推荐阅读