简体   繁体   English

如何通过 Selenium 和 Java 使用 setCapability() 忽略 Internet Explorer 的受保护模式设置?

[英]How to ignore protected Mode Settings for Internet Explorer using setCapability() through Selenium and Java?

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我正在尝试使用 IE 在 java selenium 中进行测试,但我的问题是我必须继续在保护模式下配置设置,这是已弃用功能的替代方案

WebDriver driver = new InternetExplorerDriver(cap);

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.我在 eclipse 中使用这段代码,它在我的代码中完全没有效果,上面用黄线荧光笔勾勒出来,表示它已被弃用。 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);

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 : 您需要使用MutableCapabilities类中的方法merge()DesiredCapabilities类型的对象合并到InternetExplorerOptions类型的对象中,并通过传递InternetExplorerOptions对象来初始化WebDriverWebClient实例,如下所示:

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

Thanks to the answer from DebanjanB , this was what I required.感谢DebanjanB的回答,这就是我所需要的。 But I was getting some error on DesiredCapabilities.internetExplorer();但是我在DesiredCapabilities.internetExplorer();上遇到了一些错误DesiredCapabilities.internetExplorer(); part, here is what worked for me:部分,这对我有用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在JAVA中获取Internet Explorer的文档模式 - How to fetch the document mode of Internet Explorer in JAVA Windows 7 Internet Explorer 8保护模式问题 - Windows 7 Internet Explorer 8 protected mode issue 通过 Selenium 和 Java 使用 IEDriverServer 和 Internet Explorer 在 Microsoft Dynamics CRM 中出现 XPathEvaluator 未定义脚本错误 - XPathEvaluator is undefined’ script error in Microsoft Dynamics CRM using IEDriverServer and Internet Explorer through Selenium and Java InPrivate模式下Internet Explorer中的Selenium测试 - Selenium test in Internet Explorer in InPrivate mode 使用Java将用于Firefox的Selenium IDE转换为Chrome和Internet Explorer - Convert selenium IDE for firefox to chrome and internet explorer using Java 如何使用JAVA在Selenium Webdriver的Internet Explorer中处理服务器身份验证弹出窗口? - How can i handle Server authentication pop-up in Internet Explorer in Selenium Webdriver using JAVA? Selenium-Internet Explorer-Java-如何禁用图像加载? - Selenium - Internet explorer - Java - How to disable images loading? 使用Java的Internet Explorer上运行Selenium 2.12失败 - Running Selenium 2.12 fails on Internet Explorer with Java Internet Explorer未从Java的Selenium 2.48打开 - Internet Explorer is not opening from selenium 2.48 for Java 单击Selenium with Java for Internet Explorer中的单选按钮 - Clicking a radio button in Selenium with Java for Internet Explorer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM