python - 断管错误 selenium webdriver,当命令之间存在间隙时?

标签 python selenium ubuntu selenium-webdriver

Ubuntu 18.x + selenium webdriver(Firefox)

面对一个奇怪的问题,如果我一起运行,下面的 block 就可以工作了

from selenium import webdriver
url = 'https://indiamart.com'
driver = webdriver.Firefox()
driver.get(url)
driver.find_element_by_xpath(xpath).click()

我尝试过的每个 url 都会出现这种情况。

但是如果我一次执行一行,它会给出

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 326, in get
    self.execute(Command.GET, {'url': url})
  File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 472, in execute
    return self._request(command_info[0], url, body=data)
  File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 495, in _request
    self._conn.request(method, parsed_url.path, body, headers)
  File "/usr/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1065, in _send_output
    self.send(chunk)
  File "/usr/lib/python3.6/http/client.py", line 986, in send
    self.sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe

这是代码上的错误

driver.get(url)

但是,如果我在 Broken Pipe error 之后再次执行同一行,它会工作并获取 url

我很困惑。谁能帮帮我。

谢谢

最佳答案

这是geckodriver 最新版本v0.21.0 与最新版本selenium v​​3.11 匹配的已知错误

要解决此错误,请执行以下操作: 一)downgrade geckodriver到 v0.20.1 或更早版本 b) 等待在即将推出的 selenium 和/或 geckodriver 版本中推出错误修复/缓解措施

此错误源于 Keep-Alive 功能 v 0.21 中新增的支持。但是,geckodriver 在 0.21 中的默认超时设置为 5s,非常短。

此错误已跟踪 here对于 geckodriver 和 here Selenium 。

关于python - 断管错误 selenium webdriver,当命令之间存在间隙时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51239512/

相关文章:

python - 如何使用 pandas pd.read_sql_query 使用多个参数?

Java- Selenium : <html> containing <html> problematic

javascript - Selenium/WebdriverJs/Protractor promise 与页面对象链接

python - 并行运行多个进程

python - 默认情况下使用 QTabWidget 防止使用 Ctrl+Tab 进行选项卡循环

python - 获取用户输入并将其保存到最多三个变量

java - 并行执行且使用 "priority"时出现 TestNG 问题

bash - 如何将进度条添加到 shell 脚本

ubuntu - 在 Ubuntu Server 14.04 上自动启动 Zookeeper 的最佳方式?

amazon-web-services - EBS 卷显示没有挂载点