2017-10-30 19 views
0

Firefox用のSelenium Geckodriverを私のMacでしばらく働かせるために戦っています。Selenium GeckodriverをPython上で動作させることができません - Mac OSX High Sierra

ドキュメンテーションに示されているように私は/ 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. 

答えて

0

パスをgeckodriverに設定する必要があります。方法は以下の通りです:

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

ファイルが実行可能であることを確認してください:

  • ます。chmod + xのgeckodriver ++

EDIT

したくない場合コードにexecutable_pathを指定するには、PATH環境変数にこれを追加する必要があります。

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

ありがとうございました。毎回実行可能パスを入れる必要がないように、PATHの場所に簡単に設定する方法はありますか? –

+0

@MaxMorin私は答えを編集しました –

関連する問題