无法在Selenium WebDriver Python中启动IE

时间:2017-07-22 01:30:04

标签: python selenium internet-explorer

我正在使用Selenium来自动化IE11的网页测试,我按照https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration的指示执行了所有步骤,但是当我运行自动化时仍然出错,我无法启动IE浏览器。

  1. (仅对于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子键可能存在也可能不存在,如果不存在则应该创建。在此键中,创建一个名为iexplore.exe的值为0的DWORD值。)
  2. 所有区域的保护模式设置相同
  3. 已禁用增强保护模式。
  4. 将缩放级别设置为100%
  5. 但是我仍然无法启动IE浏览器,我收到了以下错误:

    ======================================================================
    ERROR: test_contact (__main__.IETestCases)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "test_ie.py", line 528, in setUp
        IEDefault.setUp(self)
      File "test_ie.py", line 88, in setUp
        self.driver = webdriver.Ie(r'C:\Users\jzhao\WebPageTest\IEDriverServer_x64_3.4.0\IEDriverServer.exe')
      File "C:\Python27\lib\site-packages\selenium\webdriver\ie\webdriver.py", line 57, in __init__
        desired_capabilities=capabilities)
      File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 98, in __init__
        self.start_session(desired_capabilities, browser_profile)
      File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 188, in start_session
        response = self.execute(Command.NEW_SESSION, parameters)
      File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 256, in execute
        self.error_handler.check_response(response)
      File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 165, in check_response
    raise exception_class(value)
    WebDriverException: Message: Error 400: Bad Request
    Invalid URI: [http://127.0.0.1:56761/session]
    ----------------------------------------------------------------------
    

    版本:

    • Selenium 3.4.3
    • IE 11
    • Windows 7 64位
    • IEDriverServer_x64_3.4.0
    • Python 2.7.13

1 个答案:

答案 0 :(得分:0)

以下是您的问题的答案:

在使用Selenium 3.4.0IEDriverServer 3.4.0IE 11Python 3.6.1绑定时,您可以获取DesiredCapabilities类的帮助以进行一些配置以打开IE 11如下:

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

cap = DesiredCapabilities().INTERNETEXPLORER
cap['platform'] = "Win8"
cap['version'] = "11"
cap['browserName'] = "internet explorer"
cap['ignoreProtectedModeSettings'] = True
cap['nativeEvents'] = False
cap['requireWindowFocus'] = True
cap['INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS'] = True
driver=webdriver.Ie(capabilities=cap, executable_path=r'C:\Utility\BrowserDrivers\IEDriverServer.exe')

driver.get("https://www.facebook.com/")

如果这回答你的问题,请告诉我。