How to ignore protected Mode Settings for Internet Explorer using setCapability() through Selenium and Java?
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);
Enable Protected Mode must be set to the same value (enabled or disabled) for all zones
That setting will work around the problem but introduce some subtle problems. Have you not set up the Protected Modes of IE correctly? This is the correct solution to it.
Guide of this lives here:
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
Essentially just turn off protected mode in IE for each zone.
Alternatively if you really must use the override capability, then you either do two things:
Use the InternetExplorerOptions
class. Note the name of the property, it gives you a big clue it is not a good idea to use it.
var options = new InternetExplorerOptions;
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
var driver = new InternetEplorerDriver(options);
or use the RemoteWebDriver, which can take in any implementation of the ICapabilities
interface, which DesiredCapabilites
implements:
var capabilities = new DesiredCapabilities("internet explorer", string.Empty, new Platform(PlatformType.Windows));
capabilities.SetCapability("ignoreProtectedModeSettings", true);
var webDriver = new RemoteWebDriver(capabilities);
Related Topics
How to Restrict Jfilechooser to a Directory
Is There a Good Reason to Use "Printf" Instead of "Print" in Java
How to Clear or Empty a Stringbuilder
Difference Between "On-Heap" and "Off-Heap"
Compilation Error: Identifier Expected
Why We Shouldn't Make a Spring MVC Controller @Transactional
Best Option for Session Management in Java
Collections.Emptylist() VS. New Instance
Java Desktop Application: Swt VS. Swing
Dealing with Randomly Generated and Inconsistent JSON Field/Key Names Using Gson
Jackson Overcoming Underscores in Favor of Camel-Case
When to Catch the Exception VS When to Throw the Exceptions
Cannot Create Jdbc Driver of Class ' ' for Connect Url 'Null':I Do Not Understand This Exception
Java.Sql.Sqlexception: Incorrect String Value: '\Xf0\X9F\X91\Xbd\Xf0\X9F...'
Peer Not Authenticated While Importing Gradle Project in Eclipse