3

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
    exec(compile(f.read(), filename, 'exec'), namespace)

  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.

proof that gekodriver is in the right place

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.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

5

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')

Additional Consideration

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.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    This did work, but what is it about macOS that requires you to do it this way? – Makenna Sophia Herl Apr 23 '18 at 20:49
  • @MakennaSophiaHerl Not only macOS but each os behaves almost similar. – undetected Selenium Apr 23 '18 at 20:53
  • 1
    adding the executable_path argument worked for me on ubuntu(&pycharm) also ! Thanks a ton @DebanjanB, i was going crazy why it was not running when i could see the vale of my PATH environment variable was correct ! :) – ashish makani Jul 04 '19 at 08:34
  • I am running linux manjaro. Is geckodriver something that I should have by default or do I need to download it? Any hints as to where I could find it on my system? I found a geckodriver.log file (which was empty when i opened it) – Alfie Danger Nov 26 '20 at 18:08