【问题标题】:Selenium webdriver: IE crashes with "Command line server for the IE driver has stopped working"Selenium webdriver:IE 崩溃并显示“IE 驱动程序的命令行服务器已停止工作”
【发布时间】:2018-04-04 07:05:32
【问题描述】:

当尝试使用 IE 运行 Selenium Webdriver 测试时,浏览器会启动,但会立即崩溃并出现错误“IE 驱动程序的命令行服务器已停止工作”。

以下是 Python 报告的内容:

Traceback (most recent call last):
  File "tc_131.py", line 34, in <module>
    driver.set_page_load_timeout(30)
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 814, in set_page_load_timeout
    'pageLoad': int(float(time_to_wait) * 1000)})
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 306, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 464, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 526, in _request
    resp = opener.open(request, timeout=self._timeout)
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 526, in open
    response = self._open(req, data)
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 544, in _open
    '_open', req)
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1346, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1321, in do_open
    r = h.getresponse()
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

最简单的测试导致失败:

from selenium import webdriver

driver = webdriver.Ie()

driver.set_page_load_timeout(30)
driver.get('https://google.com')
driver.implicitly_wait(30)

【问题讨论】:

  • 你能分享你的完整测试吗?
  • 添加了导致失败的简单测试的文本。

标签: selenium internet-explorer webdriver


【解决方案1】:

我昨天也遇到了类似的问题:

起初我尝试使用 64 位 IEDriverServer.exe 版本 3.9.0.0 运行,并且还遇到了 ConnectionResetError: [WinError 10054]

然后我从这里下载 32 位 IEDriverServer 3.9 https://www.seleniumhq.org/download/

我的脚本现在正在运行,IE 运行良好(即使没有设置“executable_path”(添加到 PATH)和时间休眠):

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

#driver = webdriver.Ie(executable_path="C:\\webdrivers\\IEDriverServer.exe")
driver = webdriver.Ie()
#driver.set_script_timeout(5.0)
#time.sleep(3)

driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
time.sleep(5)
driver.close()

也许,你需要更新版本的 IEDriverServer 到 3.9 而且我的python版本更高3.6.5

我还添加了两个注册键(用于 32 位和 64 位路径),如设置说明中所述: https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration

我希望这会有所帮助...

【讨论】:

    【解决方案2】:

    我遇到了类似的问题,但我正在使用 c# 在这里阅读 https://github.com/SeleniumHQ/selenium/issues/6085 这解决了我的问题您可能需要通读讨论

        driver.FindElement(By.XPath("(//input[@id='Submit'])[2]")).Click();
    

    我的理解是在 IE 中,上述语法不起作用,但您可能想改用它

        IWebElement submit = driver.FindElement(By.XPath("(//input[@id='Submit'])[2]"));
            OpenQA.Selenium.Interactions.Actions buildersub = new OpenQA.Selenium.Interactions.Actions(driver);
            OpenQA.Selenium.Interactions.Actions hoverClicksub = buildersub.MoveToElement(submit).MoveByOffset(5, 5).Click();
            hoverClicksub.Build().Perform();
    

    【讨论】:

    • 虽然该链接可能会解决问题,但请在您的实际答案中包含答案的要点,因为该链接可能不可用或发生内容更改,从而使您的答案无用。
    猜你喜欢
    • 2015-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2017-07-31
    • 2023-03-19
    • 1970-01-01
    相关资源
    最近更新 更多