1

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

  • I added gecko driver to path in environment variables

  • I updated firefox to the latest version

  • I used the binary method

  • Put the geckodriver in my folder where my script is

  • I restarted my computer

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)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
coderoftheday
  • 1,987
  • 4
  • 7
  • 21

2 Answers2

1

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/')
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

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)
Yaakov Bressler
  • 9,056
  • 2
  • 45
  • 69