Selenium Chrome无法找到起始位置或冻结,Firefox工作正常

时间:2013-03-27 21:21:36

标签: python google-chrome selenium

我安装了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.

1 个答案:

答案 0 :(得分:2)

您是否已下载Chrome Driver

这款驱动程序与Google Chrome borwser一起需要。

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