Selenium webdriver:IE崩溃“IE驱动程序的命令行服务器已停止工作”

时间:2017-10-23 16:37:26

标签: selenium internet-explorer webdriver

当尝试使用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)

2 个答案:

答案 0 :(得分:0)

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

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

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

我的脚本现在正在运行,IE运行良好(即使没有设置&#34; executable_path&#34;(添加到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

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

答案 1 :(得分:0)

我遇到了类似的问题,但是我正在使用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();