selenium - 使用 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浏览器
解决方案
我找到了解决方案!
出现问题是因为 Internet Explorer 已启用保护模式,当我禁用保护模式时,它对我来说非常有效。
推荐阅读
- javascript - 这是 IE 11 中的错误吗?
- r - R ggplot 在 geom_rect 中添加注释
- sql - SQL 查询 User.first_name OR User.last_name OR 两者?
- php - PHP 将文本转换为查询
- javascript - 更新网页以包含被阻止的 iframe,但初始加载工作正常
- zeromq - ZMQ PUB SUB LOST TCP CONNECTION ON PUB 端
- sql - Oracle 查询 where field1=field2 and field2=field1
- html - 是否可以选择最近的css选择器或父级
- python - python中的平方根循环
- java - 应用程序在不显示权限对话框的情况下崩溃,但在手动授予权限时工作正常