LoginSignup
6
4

More than 5 years have passed since last update.

Selenium WebDriverのPythonバインディングでFireFox(via Homebrew-cask)を使用する

Last updated at Posted at 2015-02-20

Selenium WebDriver(Pythonバインディング)でFireFoxを使おうとした際に、以下のエラーが出た。

>>> from selenium import webdriver
>>> driver = webdriver.Firefox()
...
FileNotFoundError: [Errno 2] No such file or directory: '/Applications/Firefox.app/Contents/MacOS/firefox-bin'

引数なしでwebdriver.Firefoxを呼んだ場合、各環境毎のデフォルトのパスが使用される。(Macの場合は/Applications/Firefox.app/Contents/MacOS/firefox-bin)

(ref) https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/firefox/firefox_binary.py#L143

自身の環境ではHomebrew-Cask経由でFireFoxをインストールしており、その場合のパスは~/Applications/Firefox.app/Contents/MacOS/firefox-binになる。このパスをWebDriverに伝えるためには、以下のようにFireFoxBinaryインスタンスを与える必要がある。

>>> bin = webdriver.firefox.webdriver.FirefoxBinary('/Users/FGtatsuro/Applications/Firefox.app/Contents/MacOS/firefox')
>>> driver = webdriver.Firefox(firefox_binary=bin)
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4