2017-03-02 69 views
0

我試圖用硒啓動谷歌瀏覽器,但我得到一個錯誤 這裏是我的代碼:硒webdriver.firefox()錯誤

from selenium import webdriver 
browser = webdriver.Firefox() 
browser.get('http://localhost:8000') 
assert 'Django' in browser.title 

這裏是錯誤:

Traceback (most recent call last): 
File "functional_tests.py", line 5, in <module> 
browser = webdriver.Firefox(firefox_binary=binary) 
File "C:\Python27\lib\site- 
packages\selenium\webdriver\firefox\webdriver.py", line 140, in __init__ 
self.service.start() 
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start 
os.path.basename(self.path), self.start_error_message) 
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x03D51FD0>> ignored 

有什麼幫助嗎?

+0

我讀之前,我問..這不是一樣的錯誤 –

回答

0

確保你有最新的geckodriver和firefox安裝在默認目錄。

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH導致geckodriver問題,可以通過提供geckodriver的路徑來解決。可能的原因,geckdriver位置不會添加到PATH中。

binary = FirefoxBinary('path') 
browser = webdriver.Firefox(firefox_binary=binary) 

Exception AttributeError: "'Service' object has no attribute 'process'"看起來像我你的firefox被安裝在自定義位置。請確認。