如何通过 Selenium 和 Java 使用 setCapability() 忽略 Internet Explorer 的保护模式设置?
How to ignore protected Mode Settings for Internet Explorer using setCapability() through Selenium and Java?
我正在尝试使用 IE 在 java selenium 中进行测试,但我的问题是我必须继续在保护模式下配置设置,这是已弃用的替代方法
函数
WebDriver driver = new InternetExplorerDriver(cap);
因为我希望在没有人工交互的情况下自动执行此操作。我在 eclipse 中使用这段代码,它在我的代码中根本没有任何效果,上面用黄线荧光笔勾勒出来,表示它已被弃用。那么有没有一个新的功能来实现这里是我一直用于完整性检查的代码
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);
看来你快到了。您需要使用方法merge()
from MutableCapabilities Class将DesiredCapabilities类型的对象合并为InternetExplorerOptions类型的对象并初始化WebDriver 和 WebClient 实例通过传递 InternetExplorerOptions 对象如下:
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);
WebDriver driver = new InternetExplorerDriver(options);
感谢 DebanjanB 的回答,这正是我所需要的。但是我在 DesiredCapabilities.internetExplorer();
部分遇到了一些错误,这对我有用:
InternetExplorerOptions cap = new InternetExplorerOptions();
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);
WebDriver driver = new InternetExplorerDriver(cap);
我正在尝试使用 IE 在 java selenium 中进行测试,但我的问题是我必须继续在保护模式下配置设置,这是已弃用的替代方法 函数
WebDriver driver = new InternetExplorerDriver(cap);
因为我希望在没有人工交互的情况下自动执行此操作。我在 eclipse 中使用这段代码,它在我的代码中根本没有任何效果,上面用黄线荧光笔勾勒出来,表示它已被弃用。那么有没有一个新的功能来实现这里是我一直用于完整性检查的代码
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);
看来你快到了。您需要使用方法merge()
from MutableCapabilities Class将DesiredCapabilities类型的对象合并为InternetExplorerOptions类型的对象并初始化WebDriver 和 WebClient 实例通过传递 InternetExplorerOptions 对象如下:
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);
WebDriver driver = new InternetExplorerDriver(options);
感谢 DebanjanB 的回答,这正是我所需要的。但是我在 DesiredCapabilities.internetExplorer();
部分遇到了一些错误,这对我有用:
InternetExplorerOptions cap = new InternetExplorerOptions();
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);
WebDriver driver = new InternetExplorerDriver(cap);