python - 即使启用了ignoreProtect模式设置,Internet Explorer也未使用selenium启动

标签 python selenium internet-explorer selenium-webdriver

示例代码:

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 中的设置。它们由管理员控制。

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

最佳答案

要打开 InternetExplorer,您需要实现以下配置:

  1. 在 Windows Vista 或 Windows 7 上的 IE 7 或更高版本上,您必须将每个区域的保护模式设置设置为相同的值。该值可以是,只要每个区域都相同即可。要设置保护模式设置,请从“工具”菜单中选择“Internet 选项...”,然后单击“安全”选项卡。对于每个区域,选项卡底部都会有一个标记为“启用保护模式”的复选框。
  2. 此外,对于 IE 10 及更高版本,必须禁用增强保护模式。此选项位于 Internet 选项 对话框的高级选项卡 中。
  3. 浏览器缩放级别必须设置为100%,以便将 native 鼠标事件设置为正确的坐标。<
  4. 对于 Windows 10,您还需要在显示设置中将更改文本、应用和其他项目的大小设置为100% .
  5. 仅对于 IE 11,您需要在目标计算机上设置注册表项,以便驱动程序可以维持与其创建的 Internet Explorer 实例的连接。对于 32 位 Windows 安装,您必须在注册表编辑器中检查的项是 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE。对于 64 位 Windows 安装, key 为 HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE。请注意,FEATURE_BFCACHE 子项 可能存在也可能不存在,如果不存在则应创建它。重要提示:在此项中,创建一个名为 iexplore.exeDWORD 值,其值为 0

现在,您必须通过 DesiredCapability 使用以下设置来设置 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/')

关于python - 即使启用了ignoreProtect模式设置,Internet Explorer也未使用selenium启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48020561/

相关文章:

python - 为 Jupyter (Anaconda) 安装 Scala 内核(或 Spark/Toree)

python - pygame 敌人朝向玩家的二维运动,如何计算 x 和 y 速度?

java - Selenium 挂起实例化 FirefoxDriver

python - 在 Selenium 上切换窗口

python - 创建一组的所有组合并耗尽内存

python - 将字典的一部分与副本合并

java - WebDriverWait.until(ExpectedConditions.elementToBeClickable(someAjaxMagic)) 永远不会返回

javascript - IE 中的不透明度属性

javascript - 如何在加载 jQuery 时使用 SVGweb 嵌入 SVG(即问题)

Javascript - Opera 11.60 和 IE 8 上的排序功能问题