# WebDriverException: 'geckodriver' executable needs to be in PATH even though it is

Trying to get firefox to run using selenium in spyder. My current code is

from selenium import webdriver
import os
os.environ["PATH"] += ":/usr/local/bin/geckodriver"
browser = webdriver.Firefox()


and I still get this error:

runfile('/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder/test.py',
wdir='/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder')
Traceback (most recent call last):

File "<ipython-input-1-3f3f96ccf515>", line 1, in <module>

runfile('/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder/test.py',
wdir='/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder')

File "/Applications/anaconda3/lib/python3.6/site-
packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
execfile(filename, namespace)

File "/Applications/anaconda3/lib/python3.6/site-
packages/spyder/utils/site/sitecustomize.py", line 102, in execfile

File "/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder/test.py",
line 12, in <module>
browser = webdriver.Firefox()

File "/Applications/anaconda3/lib/python3.6/site-
packages/selenium/webdriver/firefox/webdriver.py", line 152, in
__init__
self.service.start()

File "/Applications/anaconda3/lib/python3.6/site-
packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)

WebDriverException: 'geckodriver' executable needs to be in PATH.


Even though gekodriver is in that folder.

I have also tried exporting the path to ~./bash_profile which looks like this right now.

Last login: Fri Apr 20 10:57:16 on ttys000
dhcp-54-85:~ mherl$nano ./bash_profile dhcp-54-85:~ mherl$ nano .bash_profile
GNU nano 2.0.6             File: .bash_profile
Modified

# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}" export PATH # Setting PATH for Python 3.6 # The original version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH

# added by Anaconda3 5.1.0 installer
export PATH="/Applications/anaconda3/bin:$PATH" #added by mherl to show path to gekodriver export PATH=$PATH:/usr/local/bin/gekodriver


I also have the current paths set in spyder:

/usr/local/bin
/Users/mherl/Dropbox/AnacondaProjects/MWS/MWSSpyder


of which gekodriver is in

/usr/local/bin


I have looked everywhere and most people say it should run automatically if it's in /usr/local/bin but it still can't seem to find it even when I explicitly state the path.

This is a mac running High Sierra if that's important.

59

This error message...

WebDriverException: 'geckodriver' executable needs to be in PATH.


...implies that the GeckoDriver wasn't found in the expected default location.

## Solution

As you are using MAC based System you need to pass the Key executable_path along with the Value referring to the absolute path of the GeckoDriver as follows :

from selenium import webdriver

browser = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')


Ensure the following :

• GeckoDriver is present in the specified location.
• GeckoDriver is having executable permission for non-root users.
• Execute your @Test as a non-root user.
Tuesday, June 1, 2021

49

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

First of all you will need to download latest executable geckodriver from here to run latest Firefox using Selenium

Actually, the Selenium client bindings tries to locate the geckodriver executable from the system PATH. You will need to add the directory containing the executable to the system path.

• On Unix systems you can do the following to append it to your system’s search path, if you’re using a Bash-compatible shell:

  export PATH=\$PATH:/path/to/directory/of/executable/downloaded/in/previous/step

• On Windows you will need to update the Path system variable to add the full directory path to the executable geckodriver manually or command line** (don't forget to restart your system after adding executable geckodriver into system PATH to take effect)**. The principle is the same as on Unix.

Now you can run your code same as you're doing as below :-

from selenium import webdriver

browser = webdriver.Firefox()


selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line

The exception clearly states you have installed Firefox some other location while Selenium is trying to find Firefox and launch from the default location, but it couldn't find it. You need to provide explicitly Firefox installed binary location to launch Firefox as below :-

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

binary = FirefoxBinary('path/to/installed firefox binary')
browser = webdriver.Firefox(firefox_binary=binary)


https://github.com/mozilla/geckodriver/releases

For Windows:

Download the file from GitHub, extract it, and paste it in Python file. It worked for me.

https://github.com/mozilla/geckodriver/releases

For me, my path path is:

C:UsersMYUSERNAMEAppDataLocalProgramsPythonPython39

Tuesday, June 1, 2021

100

The error says it all :

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.


Which implies that GeckoDriver binary is not in the Classpath

While working with Selenium v3.x you have to download the latest GeckoDriver from this url and store it in your system and mention the absolute path while initiating the webdriver and Web Browser session as follows :

from selenium import webdriver

driver = webdriver.Firefox(executable_path="C:\path\to\geckodriver.exe")
button.click()

Wednesday, June 2, 2021

21

This error message...

selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities


...implies that the GeckoDriver was unable to initiate/spawn a new WebBrowsing Session i.e. Firefox Browser session.

Your main issue may be the incompatibility between the version of the binaries you are using as follows:

## Solution

• Upgrade Selenium to current levels Version 3.141.59.
• Upgrade GeckoDriver to GeckoDriver v0.23.0 level.
• Ensure GeckoDriver is present in the specified location.
• Ensure GeckoDriver is having executable permission for non-root users.
• Upgrade Firefox version to Firefox v64.0. levels.
• (WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
• (LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
• If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
• Take a System Reboot.
• Pass the argument executable_path along with the absolute path of the GeckoDriver while initiating the WebDriver/WebBrowser session as follows:

• Windows OS format:

driver = webdriver.Firefox(executable_path=r'C:pathtogeckodriver.exe')

• Linux and MAC OS X format:

driver = webdriver.Firefox(executable_path='/path/to/geckodriver')

• Execute your Test as a non-root user.

• Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Thursday, June 3, 2021

70

Yeah, it's a bug on the geckodriver. You can find it here!

Wednesday, August 18, 2021