【问题标题】:Selenium Chrome either can't find start location or freezes, Firefox works fineSelenium Chrome 找不到开始位置或死机,Firefox 工作正常
【发布时间】:2013-03-27 21:21:36
【问题描述】:

我安装了 Selenium,也安装了 Chrome。我在linux上使用python绑定。 Firefox 工作正常,但我无法让 Chrome 工作。

如果我没有在 chrome 驱动程序中指定参数,我会得到:

>>> driver = webdriver.Chrome()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 60, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/service.py", line 68, in start
    and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.                 Please download from http://code.google.com/p/selenium/downloads/list                and read up at http://code.google.com/p/selenium/wiki/ChromeDriver' 

然后我阅读了那个链接。它说 selenium 期望安装 chrome 的位置是/usr/bin/google-chrome

我查了一下,果然……

$ which google-chrome 
/usr/bin/google-chrome

所以,再试一次,带参数:

>>> driver = webdriver.Chrome('/usr/bin/google-chrome')

太好了,Chrome 启动了,所以我知道 webdriver 可以找到它。但是,任务没有完成。它运行并挂起。与 Firefox 不同,运行它不会释放对脚本的控制。我必须按 ctrl-C 来夺取控制权,并且无​​法使用驱动程序对象。

另一方面,在 Firefox 中...

>>> driver = webdriver.Firefox()
>>> driver.method # etc.

【问题讨论】:

    标签: python google-chrome selenium


    【解决方案1】:

    你下载Chrome Driver了吗?

    此驱动程序是与 google chrome borwser 一起需要的。

    要进行设置,请先下载相应的预构建服务器。确保服务器可以位于您的 PATH 或通过 webdriver.chrome.driver 系统属性指定其位置。

    【讨论】:

    • 是的,我已经安装了---你知道设置路径的命令是什么吗?我家也有,还是找不到。 webdriver.chrome.options.Options.binary_location ="~/" 失败,除此之外......
    猜你喜欢
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 2015-05-03
    • 2016-08-01
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    相关资源
    最近更新 更多