【问题标题】:Try to start chrome driver on linux with selenium webdriver尝试使用 selenium webdriver 在 linux 上启动 chrome 驱动程序
【发布时间】:2014-11-16 11:42:17
【问题描述】:

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

我写了一个简单的测试

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 版本 3.13.0-35-generic (buildd@roseapple)(gcc 版本 4.8.2 (Ubuntu 4.8.2-19ubuntu1))#62-Ubuntu SMP Fri Aug 15 01:58:01 UTC 2014

请帮帮我:(

【问题讨论】:

    标签: python linux selenium selenium-chromedriver


    【解决方案1】:

    对于 Linux 用户:

    在启动 Chrome 之前启动 Display。更多信息请点击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()
    

    【讨论】:

    • 为什么大家都赞成一个与问题完全无关的答案?
    【解决方案2】:

    2.10.267517 不是最新版本。

    $ chromedriver --version
    ChromeDriver 2.10.267518
    

    使用以上版本 Python 2.7.6,您的代码运行良好。 (除了我修改了chromedriver路径)

    仅供参考,这里是我的 ubuntu 的 unname:

    $ uname -a
    Linux jmlee12 3.13.0-36-generic #63-Ubuntu SMP Wed Sep 3 21:30:07 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
    $ python -V
    Python 2.7.6
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-04
    • 2013-10-16
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 2013-06-08
    • 1970-01-01
    相关资源
    最近更新 更多