coderoftheday
coderoftheday

Reputation: 2075

'geckodriver' executable needs to be in PATH using GeckoDriver and Firefox through Selenium

I'm very familiar with using chromedriver for selenium, im now trying to using geckdriver instead but for some reason I keep getting the error 'geckodriver' executable needs to be in PATH.

I followed the steps in Selenium using Python - Geckodriver executable needs to be in PATH

But none of these methods seem to work, is there something I'm missing?

Here's my code

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary


binary = FirefoxBinary("C:\\Users\\ojadi\\Downloads\\geckodriver-v0.28.0-win64\\geckodriver.exe")
browser = webdriver.Firefox(firefox_binary=binary)

Upvotes: 1

Views: 3059

Answers (2)

Yaakov Bressler
Yaakov Bressler

Reputation: 12018

Two settings which are often overlooked in installation guides:

  1. Including geckodriver executable in your profile
  2. Enabling geckodriver executable

MAC: To add geckodriver to your profile:

  1. Open your zsh profile: open ~/.zshrc
  2. Add the following line of code to your profile: export PATH=$PATH:/usr/local/bin/geckodriver (Assuming this is the location of your geckodriver, if not, replace with location.)
  3. Save and close.
  4. Reload your profile (or restart terminal): source ~/.zshrc

MAC: To make geckodriver executable:

  1. sudo chmod +x /usr/local/bin/geckodriver (or path to geckodriver exectable)

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193098

You can download and store the GeckoDriver executable anywhere with in your system and you need to do pass the absolute path of firefox binary through the attribute binary_location as follows:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
driver = webdriver.Firefox(firefox_options=options, executable_path=r'C:\Users\\ojadi\Downloads\geckodriver-v0.28.0-win64\geckodriver.exe')
driver.get('http://google.com/')

Upvotes: 1

Related Questions