【问题标题】:Internet Explorer not launched using selenium even though ignoreProtect mode settings are enabled即使启用了忽略保护模式设置,Internet Explorer 也未使用 selenium 启动
【发布时间】:2017-12-29 09:49:26
【问题描述】:

示例代码:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.INTERNETEXPLORER
caps['ignoreProtectedModeSettings'] = True

browser = webdriver.Ie(capabilities=caps)
browser.get('http://www.google.com')

Internet Explorer 未启动,我面临以下错误:

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.

我无法更改 InternetExplorer 中的设置。它们由管理员控制。

我只停留在这个起点,有人可以帮忙吗?

【问题讨论】:

标签: python selenium internet-explorer selenium-webdriver


【解决方案1】:

要打开InternetExplorer,您需要实现以下Configurations

  1. 在 IE 7 或更高版本的 Windows Vista 或 Windows 7 上,您必须将每个区域的 Protected Mode settings 设置为相同的值。该值可以是 onoff,只要每个区域都相同。要设置保护模式设置,请从“工具”菜单中选择“Internet 选项...”,然后单击“安全”选项卡。对于每个区域,标签底部都有一个标记为“启用保护模式”的复选框。
  2. 此外,必须为 IE 10 and higher 禁用 Enhanced Protected Mode。此选项位于Internet Options 对话框的Advanced tab 中。
  3. 必须将浏览器zoom level 设置为100%,以便将本机鼠标事件设置为正确的坐标。
  4. 对于Windows 10,您还需要在显示设置中将Change the size of text, apps, and other items 设置为100%
  5. 仅对于IE 11,您需要在目标计算机上设置一个注册表项,以便驱动程序可以保持与其创建的 Internet Explorer 实例的连接。对于 32 位 Windows 安装,您必须在注册表编辑器中检查的键是 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE。对于 64 位 Windows 安装,密钥是 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE。请注意,FEATURE_BFCACHE subkey 可能存在也可能不存在,如果不存在则应创建。重要提示:在此键中,创建一个名为 iexplore.exeDWORD 值,其值为 0

现在,您必须通过 DesiredCapabilities 使用以下设置设置 IEDriverServer 二进制文件:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

cap = DesiredCapabilities().INTERNETEXPLORER
cap['ignoreProtectedModeSettings'] = True
cap['IntroduceInstabilityByIgnoringProtectedModeSettings'] = True
cap['nativeEvents'] = True
cap['ignoreZoomSetting'] = True
cap['requireWindowFocus'] = True
cap['INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS'] = True
browser = webdriver.Ie(capabilities=cap, executable_path=r'C:\path\to\IEDriverServer.exe')
browser.get('http://google.com/')

【讨论】:

  • 由于我的系统由管理员控制,我无权更改 IE 中的受保护模式设置。是否有可能通过其他方法克服这一步?
  • 我的解决方案包含一些代码来解决您在protected Mode settings 中遇到的问题。试试代码,让我们的数字保持交叉:)
猜你喜欢
  • 2019-01-14
  • 1970-01-01
  • 1970-01-01
  • 2015-12-22
  • 1970-01-01
  • 1970-01-01
  • 2018-09-25
  • 1970-01-01
  • 2023-04-10
相关资源
最近更新 更多