python - 尝试使用 selenium webdriver 在 linux 上启动 chrome 驱动程序

标签 python linux selenium selenium-chromedriver

我试图找到答案,但找不到,现在我自己问。

我写了简单的测试

from selenium import webdriver

driver = webdriver.Chrome(executable_path=r"/home/tranter/workspace/chromedriver")
driver.get("http://www.python.org")
driver.close()

比我有回溯

> tranter@tranter-VirtualBox:~/workspace$ python testchrome.py Traceback
> (most recent call last): File "testchrome.py", line 6, in <module>
> driver =
> webdriver.Chrome(executable_path=r"/home/tranter/workspace/chromedriver")
> File
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py",
> line 65, in __init__ keep_alive=True) File
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
> line 73, in __init__ self.start_session(desired_capabilities,
> browser_profile) File
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
> line 121, in start_session 'desiredCapabilities':
> desired_capabilities, File
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
> line 173, in execute self.error_handler.check_response(response) File
> "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py",
> line 166, in check_response raise exception_class(message, screen,
> stacktrace) selenium.common.exceptions.WebDriverException: Message:
> u'unknown error: Chrome failed to start: exited abnormally\n (Driver
> info: chromedriver=2.10.267517,platform=Linux 3.13.0-35-generic x86)'

我有最新版本的 chromedriver 10、最新的 chromium、最新的 selenium webdriver。 而这一切都是我在 xubuntu 中开始的

Linux version 3.13.0-35-generic (buildd@roseapple) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #62-Ubuntu SMP Fri Aug 15 01:58:01 UTC 2014

请帮帮我:(

最佳答案

对于 Linux 用户:

在启动 Chrome 之前启动显示。有关更多信息,请单击 here

from selenium import webdriver
from pyvirtualdisplay import Display
# Add following 2 line before start the Chrome
display = Display(visible=0, size=(800, 800))  
display.start()
driver = webdriver.Chrome()
driver.get("http://www.google.com")
driver.quit()
display.stop()

关于python - 尝试使用 selenium webdriver 在 linux 上启动 chrome 驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25975241/

相关文章:

python - 使用 Pandas 如何根据日期查找列中某些元素的平均值?

python - 在 FLASK 应用程序中同时运行 Celerybeat 和 Worker

ruby-on-rails - rails : How to pass data to Bash Script

linux - 从配置文件命令运行 tmux 时 iterm 损坏管道

xml - 在一个字段 XML 中复制数据

python - 为什么我会收到 FileNotFoundError?

python - 如何使用 boto3 部署 AWS 无服务器应用程序模型模板?

python - 使用 Selenium 和 Beautifulsoup 解析 Airdna map 悬停在文本上

c# - 如何在 C# Selenium 中使用鼠标事件?

r - 如何使用 xpath 检查某个对象在网页中是否可见?