使用 Selenium 的 Internet Explorer 驱动程序在访问外部网页时不允许处理 window

Internet explorer driver with Selenium does not allow to handle the window when accessing external web pages

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

org.openqa.selenium.NoSuchWindowException: Error retrieving current window at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.setPosition(RemoteWebDriver.java:807) at 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浏览器

我找到了解决办法!

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