【问题标题】:WebDriverException() in Python2.7 using xvfb-run for chrome on Amazon Linux AMI Red-hat 7.2Python2.7 中的 WebDriverException() 在 Amazon Linux AMI Red-hat 7.2 上使用 xvfb-run for chrome
【发布时间】:2018-12-20 07:30:26
【问题描述】:

尝试通过

运行 selenium for chrome
/usr/bin/xvfb-run -a -e /tmp/selenium.log -w 0 /usr/bin/python2.7 

并得到像

这样的错误
(<class 'selenium.common.exceptions.WebDriverException'>, WebDriverException(), <traceback object at 0x7fc7cfc9c128>)

奇怪的是我什至没有得到完整的堆栈跟踪,xvfb-run 的-e 选项也没有在文件中返回任何错误。

这是我的代码

from selenium import webdriver 
from selenium.webdriver.chrome.options import Options 
f = webdriver.ChromeOptions() 
browser =webdriver.Chrome(executable_path='/home/local/chromedriver',chrome_options=f) 
browser.get(url)
browser.quit()

我也试过 executable_path='/usr/bin/chromedriver' 并且没有 executable_path

但得到同样的错误。

它最初是使用带有 firefox 的 python 2.6

我检查了大约 10-15 个类似的问题,甚至关于如何启用更多跟踪或调试,但似乎没有一个解决方案在这里对我有用。

硒版本 3.141.0

编辑: 我更新了一些代码以便能够获得完整的堆栈跟踪,但我得到了这个错误,

WebDriverException:消息:浏览器之前似乎已经退出 我们可以连接。

多一点挖掘,发现它与硒/浏览器有关 安装旧的 selenium 版本 2.53

因此上面的错误消失了,但现在我正在通过对等错误重置连接,下面是堆栈

(<class 'socket.error'>, error(104, 'Connection reset by peer'), <traceback object at 0x1e1e320>)
Traceback (most recent call last):
  File "/var/www/Goose/src/goose/network.py", line 137, in get_html
    browser.get(url)
  File "/var/www/Goose/src/selenium/webdriver/remote/webdriver.py", line 245, in get
    self.execute(Command.GET, {'url': url})
  File "/var/www/Goose/src/selenium/webdriver/remote/webdriver.py", line 231, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/var/www/Goose/src/selenium/webdriver/remote/remote_connection.py", line 395, in execute
    return self._request(command_info[0], url, body=data)
  File "/var/www/Goose/src/selenium/webdriver/remote/remote_connection.py", line 426, in _request
    resp = self._conn.getresponse()
  File "/usr/lib64/python2.6/httplib.py", line 1049, in getresponse
    response.begin()
  File "/usr/lib64/python2.6/httplib.py", line 433, in begin
    version, status, reason = self._read_status()
  File "/usr/lib64/python2.6/httplib.py", line 389, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib64/python2.6/socket.py", line 479, in readline
    data = self._sock.recv(self._rbufsize)
error: [Errno 104] Connection reset by peer

即使requests [security] 已安装,因为我已经看到了一个原因。

【问题讨论】:

  • 使用错误堆栈跟踪更新问题。我们需要知道(&lt;class 'selenium.common.exceptions.WebDriverException'&gt;, WebDriverException(), &lt;traceback object at 0x7fc7cfc9c128&gt;) 来自哪一行。
  • @DebanjanB ,编辑添加更多信息,

标签: python-2.7 selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

解决了 问题是chrome浏览器和驱动程序没有正确安装,并且它们的版本不兼容,

使用我从中获得的脚本安装了最新的 chrome 以在 ami 服务器上运行 https://intoli.com/blog/installing-google-chrome-on-centos/

安装完美, 添加了一些关键参数,

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('path to driver',chrome_options=chrome_options)

中提琴开始工作了,

【讨论】:

    猜你喜欢
    • 2016-11-22
    • 2017-06-24
    • 2019-04-02
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 2020-07-13
    • 2013-03-03
    • 2018-06-02
    相关资源
    最近更新 更多