簡體   English   中英

無法讓Selenium Geckodriver在Python上運行-Mac OSX High Sierra

[英]Unable to get Selenium Geckodriver to work on Python - Mac OSX High Sierra

我一直在努力讓Firefox的Selenium Geckodriver在我的Mac上運行一段時間,但我無法使其正常運行。

如文檔所示,我的/ usr / local / bin /目錄中有geckodriver二進制文件。

每當我嘗試執行以下命令時:

from selenium import webdriver
browser = webdriver.Firefox()
type(browser)
browser.get('www.google.com')enter code here

我在Python控制台中收到以下錯誤。

Traceback (most recent call last):
  File "/Users/maxmorin/.thonny/BundledPython36/lib/python3.6/site-
packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
  File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 707, in __init__
restore_signals, start_new_session)
  File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1326, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/maxmorin/Google Drive/Support Team Python Code/Max's Projects/Release Readiness/selenium_test.py", line 2, in <module>
browser = webdriver.Firefox()
  File "/Users/maxmorin/.thonny/BundledPython36/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 144, in __init__
self.service.start()
  File "/Users/maxmorin/.thonny/BundledPython36/lib/python3.6/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. 

您必須設置壁虎驅動程序的路徑。 一種方法如下:

driver = webdriver.Firefox(profile, executable_path=r'/pathTo/geckodriver')
driver.get("https://www.google.com")

確保該文件是可執行文件:

  • chmod + x壁虎驅動程序++

編輯

如果您不想在代碼中指定可執行文件路徑,則必須在PATH環境變量中添加它:

export PATH=$PATH:/path/to/geckodriver

暫無
暫無

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

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