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

核能气质少年 提交于 2019-11-26 09:14:50

问题


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

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

回答1:


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


来源:https://stackoverflow.com/questions/51729275/how-to-ignore-protected-mode-settings-for-internet-explorer-using-setcapability

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!