[英]Unable to Launch IE from Selenium - Protected Mode settings are not the same for all zones
I am trying to lauch IE using below code:我正在尝试使用以下代码启动 IE:
driver = webdriver.Ie("IEDriverServer.exe")
driver.get("https://www.google.com")
This was working earlier, But i tried changing the security level in internet options, and after that it is giving below error:这在早些时候工作,但我尝试更改互联网选项中的安全级别,然后它给出以下错误:
selenium.common.exceptions.SessionNotCreatedException: Message: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones.
I saw many people mentioning this issue and saying that this can be fixed by using Default levels in security tab.我看到很多人提到这个问题,并说这可以通过使用安全选项卡中的默认级别来解决。 I have tried this but still i am getting same issue.
我已经尝试过了,但我仍然遇到同样的问题。 Also stried resetting ie settings:
还尝试重置即设置:
You should go to each zone screen (Internet, Local Internet, Trusted Sites, Restricted Sites) and set for each the same level.您应该 go 到每个区域屏幕(Internet、本地 Internet、受信任站点、受限制站点)并为每个相同级别设置。 For example "Medium".
例如“中”。
When you click on "Reset all zones to default", this makes some zones Medium, some High, so they are not the same any more.当您单击“将所有区域重置为默认值”时,这会使一些区域为中等,一些为高,因此它们不再相同。 And as the error message suggests, Selenium requires them to be the same.
正如错误消息所示,Selenium 要求它们相同。
Update : If for one of the zones the slide bar is disabled, you can try to run IE as Administrator, to see if this way it gets enabled.更新:如果其中一个区域的滑动条被禁用,您可以尝试以管理员身份运行 IE,以查看它是否以这种方式启用。
If this doesn't work, set all other zones to the same value, as the zone that you can't change.如果这不起作用,请将所有其他区域设置为与您无法更改的区域相同的值。
I was not able to fix the issue by manually changing the setting(few of them were disabled for me including the checkbox), but the below VBA code did the trick for me.我无法通过手动更改设置来解决这个问题(其中很少有人被禁用,包括复选框),但下面的 VBA 代码对我有用。
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 this code into notepad and save it with.vbs extension and do a double click!只需将此代码复制到记事本中并使用.vbs 扩展名保存并双击!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.