簡體   English   中英

Selenium Webdriver無法在Firefox中使用Firefox

[英]Selenium webdriver not working in python with firefox

我安裝了最新的firefox瀏覽器和硒。 我嘗試運行以下代碼:

from selenium import webdriver

browser = webdriver.Firefox()

...並收到以下錯誤:

Traceback (most recent call last):
  File "C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 992, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\download2.py", line 3, in <module>
    browser = webdriver.Firefox()
  File "C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 152, in __init__
    self.service.start()
  File "C:\Users\alisy\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 

我已經下載了geckodriver,並在PATH中指定了位置(然后重新啟動了筆記本電腦)。 Firefox也一樣。 沒關系。 我該怎么辦?

這行代碼為我解決了問題

driver=webdriver.Firefox(executable_path="c:/drivers/geckodriver.exe")

暫無
暫無

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

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