5

I am trying to use the Selenium Internet Explorer driver but it is breaking when I try to instantiate it:

[TestInitialize]
public void TestInitialise() {
  ieDriver = new InternetExplorerDriver();
}

with the following error:

Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (NoSuchDriver).

I have found an apparent solution to my problem here, which suggests setting the driver's DesiredCapabilities, as shown:

var capabilitiesInternet = new OpenQA.Selenium.Remote.DesiredCapabilities();
capabilitiesInternet.SetCapability("ignoreProtectedModeSettings", true);
IWebDriver webDriver = new InternetExplorerDriver(capabilitiesInternet);

The only problem is, I am using the latest version of the driver that I could find, and there is no override for InternetExplorerDriver that takes DesiredCapabilities as a parameter.

Is there some new or other way of setting DesiredCapabilites now instead of the example that I used?

DevDave
  • 6,700
  • 12
  • 65
  • 99

4 Answers4

8

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);
Ringil
  • 6,277
  • 2
  • 23
  • 37
Arran
  • 24,648
  • 6
  • 68
  • 78
  • thanks for the answer Arran, very helpful. But if it doesn't work without it how can it be a bad idea to use that option? – DevDave Nov 14 '12 at 17:42
  • It doesn't need the option to work, you should just be able to set the Protected Mode in each zone in IE, and it should work without needing to use the option. Why the IEDriver requires this can be found here: http://jimevansmusic.blogspot.co.uk/2012/08/youre-doing-it-wrong-protected-mode-and.html ...does that make sense? – Arran Nov 14 '12 at 18:50
  • I have set protected mode off in every zone and still get a warning about my local site's security certificate, my problem is that Selenium will not proceed past this warning. Any ideas how to get around this? – DevDave Nov 14 '12 at 19:15
  • Just to confirm, it's off for all 4 zones? (Internet, Local intranet, Trusted sites, Restricted sites). – Arran Nov 14 '12 at 19:17
  • Do you get an SSL warning you mean? If so, that's something different. – Arran Nov 14 '12 at 19:25
  • yes i did set it off for all zones. Although I did it by manually starting IE myself, I assume that will also affect IE as opened by Selenium? – DevDave Nov 15 '12 at 10:35
2

This blog post by Jim Evans (a Selenium contributor) gives a really in depth view of the context surrounding this exception. I will quote it here for posterity:

In IE, from the Tools menu (or the gear icon in the toolbar in later versions), select "Internet options." Go to the Security tab. At the bottom of the dialog for each zone, you should see a check box labeled "Enable Protected Mode." Set the value of the check box to the same value, either checked or unchecked, for each zone. Here's the dialog for reference:

Internet Explorer Security Settings Dialog

Note that you don't have to change the slider for security level, and you don't have to disable Protected Mode. I routinely run with Protected Mode turned on for all zones, as I think it provides a more secure browsing experience.

Note: This only worked for me when turning protected mode off.

Community
  • 1
  • 1
Alex W
  • 37,233
  • 13
  • 109
  • 109
0

I couldn't modify the protected mode settings manually on my system since they were disabled. But the below VBA snippet for updating the registry values did the trick for me.

Const HKEY_CURRENT_USER = &H80000001
strComputer = "."

Set ScriptMe=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

'Disable protected mode for local intranet'
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1\"
strValueName = "2500"
dwValue = 0
ScriptMe.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

'Disable protected mode for trusted pages'
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2\"
strValueName = "2500"
dwValue = 0
ScriptMe.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

'Disable protected mode for internet'
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\"
strValueName = "2500"
dwValue = 0
ScriptMe.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

'Disable protected mode for restricted sites'
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\4\"
strValueName = "2500"
dwValue = 0
ScriptMe.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

msgbox "Protected Mode Settings are updated"

Just copy paste the above code into notepad and save it with .vbs extension and double click it!

Now try running your automation script again

anandhu
  • 686
  • 2
  • 13
  • 40
-2

This Question and Answer may also be of use to anyone trying to deal with Protected Mode issues. I couldn't get it to work via the Internet Explorer Options pane and ended up having to adjust the registry manually.

Community
  • 1
  • 1
Peter Bernier
  • 8,038
  • 6
  • 38
  • 53