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

落花浮王杯 提交于 2020-12-10 00:34:29

问题


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?


回答1:


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



回答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.




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/13383773/enable-protected-mode-must-be-set-to-the-same-value-enabled-or-disabled-for-al

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