如何通过 Selenium 和 Java 使用 setCapability() 忽略 Internet Explorer 的受保护模式设置? [英] How to ignore protected Mode Settings for Internet Explorer using setCapability() through Selenium and Java?

查看:38
本文介绍了如何通过 Selenium 和 Java 使用 setCapability() 忽略 Internet Explorer 的受保护模式设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 IE 在 java selenium 中进行测试,但我的问题是我必须继续在保护模式下配置设置,这是不推荐使用的替代方案功能

I am trying to test in java selenium with IE but my problem is I have to keep on configuring the settings in protected Mode, is the an alternative to the deprecated function

WebDriver driver = new InternetExplorerDriver(cap);

因为我希望在没有人工交互的情况下实现自动化.我在 eclipse 中使用了这段代码,它在我的代码中完全没有效果,上面用黄线荧光笔勾勒出来,表示它已被弃用.那么是否有一个新功能来实现这一点,这是我一直在使用的用于完整性检查的代码

As I would like to have this automated without human interaction. I am using this code in eclipse and it has no effect at all in my code the above is stroked out with a yellow line highlighter and that says it has been deprecated. So is there a new function to achieve this here is the code I have been using just for sanity check

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() 来自 MutableCapabilitiesDesiredCapabilities 类型的对象合并到InternetExplorerOptions 类型对象并通过传递 InternetExplorerOptions 对象来启动 WebDriverWebClient 实例,如下所示:

It seems you were almost there. You need to use the method merge() from MutableCapabilities Class to merge the DesiredCapabilities type of object into InternetExplorerOptions type object and initiate the WebDriver and WebClient instance by passing the InternetExplorerOptions object as follows :

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);

这篇关于如何通过 Selenium 和 Java 使用 setCapability() 忽略 Internet Explorer 的受保护模式设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆