即使启用了ignoreProtect模式设置,也无法使用selenium启动Internet Explorer

问题描述 投票:1回答:1

示例代码:

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个回答
1
投票

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

  1. 在Windows Vista或Windows 7上的IE 7或更高版本上,必须将每个区域的Protected Mode settings设置为相同的值。只要每个区域的值相同,该值就可以打开或关闭。要设置保护模式设置,请从“工具”菜单中选择“Internet选项...”,然后单击“安全”选项卡。对于每个区域,标签底部将显示一个标记为“启用保护模式”的复选框。
  2. 此外,Enhanced Protected Mode必须禁用IE 10 and higher。此选项位于Advanced tab对话框的Internet Options中。
  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.exe的DWORD值,其值为0。

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

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/')
© www.soinside.com 2019 - 2024. All rights reserved.