簡體   English   中英

Selenium Chrome無法找到起始位置或凍結,Firefox運行正常

[英]Selenium Chrome either can't find start location or freezes, Firefox works fine

我已經安裝了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' 

然后,我閱讀了該鏈接。 它說硒希望安裝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.

您是否已下載Chrome驅動程序

該驅動程序是與google chrome瀏覽器協同工作所必需的。

要進行設置,請先下載適當的預構建服務器。 確保服務器可以位於您的PATH上,或通過webdriver.chrome.driver系統屬性指定其位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM