1

我正在尝试使用以下代码启动 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.

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

在此处输入图像描述

4

2 回答 2

0

您应该转到每个区域屏幕(Internet、本地 Internet、受信任的站点、受限制的站点)并为每个区域设置相同的级别。例如“中”。

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

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

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

于 2020-06-08T12:26:43.690 回答
0

我无法通过手动更改设置来解决问题(其中很少有人被禁用,包括复选框),但下面的 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 扩展名保存并双击!

于 2020-08-23T04:29:19.487 回答