【问题标题】:Unable to Launch IE from Selenium - Protected Mode settings are not the same for all zones无法从 Selenium 启动 IE - 所有区域的保护模式设置都不相同
【发布时间】:2020-06-08 05:26:21
【问题描述】:

我正在尝试使用以下代码启动 IE:

driver = webdriver.Ie("IEDriverServer.exe")
driver.get("https://www.google.com")

这在早期工作,但我尝试更改互联网选项中的安全级别,然后它给出以下错误:

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.

我看到很多人提到这个问题,并说这可以通过使用安全选项卡中的默认级别来解决。我已经尝试过了,但我仍然遇到同样的问题。还尝试重置即设置:

【问题讨论】:

    标签: selenium-webdriver selenium-iedriver iedriverserver


    【解决方案1】:

    您应该转到每个区域屏幕(互联网、本地互联网、可信站点、受限站点)并为每个相同级别进行设置。例如“中”。

    当您单击“将所有区域重置为默认值”时,这会使一些区域为中等,一些为高,因此它们不再相同。正如错误消息所示,Selenium 要求它们相同。

    更新:如果其中一个区域的滑动条被禁用,您可以尝试以管理员身份运行 IE,以查看是否以这种方式启用。

    如果这不起作用,请将所有其他区域设置为与您无法更改的区域相同的值。

    【讨论】:

    • 没用。我在我的办公室笔记本电脑上工作。在我的 ie 中,我只能更改 Internet、Local 和 Truested 选项卡的滑块。另一个,受限制的站点是灰色的。我也不能编辑启用保护模式复选框。
    【解决方案2】:

    我无法通过手动更改设置来解决问题(其中一些设置对我来说是禁用的,包括复选框),但下面的 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"
    

    只需将此代码复制到记事本中并以 .vbs 扩展名保存并双击!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-30
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多