Unable to Run Selenium with Firefox (Python)

459 views Asked by At

I am completely unable to get Selenium (3.0.1) to work with Firefox (50.1.0) after the update. Here is the code that I am running with the associated errors:

from selenium import webdriver

website = 'www.google.com'

driver = webdriver.Firefox() 
driver.get(website)

This gives the following errors:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver'executable needs to be in PATH.

I have read numerous posts talking about the need to add various executable files to my PATH variable in order to run Selenium, but I have thus far completely failed. My current PATH variable is the following:

$echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

I have not been able to successfully append the firefox or geckodriver executable files. It appears to be there already (I've copied the executable to '/usr/local/bin', and it's still giving me the same error. Any and all help is greatly appreciated (Mac OS X user)

3

There are 3 answers

0
Zach Escalante On

As usual, given a week of not working on this, then re-googling the problem, I was able to solve it. The hint that helped me was given in this link:

Selenium in Python on Mac - Geckodriver executable needs to be in PATH

I wasn't adding the geckodriver.exe file to the right path. When I downloaded and moved the file to my anaconda bin, it worked just fine:

mv geckodriver /anaconda/bin #after navigating to my downloads

Hope this helps!

0
IslamTaha On

You can have to install geckodriver and add it yo your execution path. Use the following bash command to install the latest geckodriver:

which geckodriver || (wget https://github.com/mozilla/geckodriver/releases/download/v0.14.0/geckodriver-v0.14.0-linux64.tar.gz -O /tmp/geckodriver.tar.gz && tar -C /opt -xzf /tmp/geckodriver.tar.gz && chmod 755 /opt/geckodriver && ln -fs /opt/geckodriver /usr/bin/geckodriver && ln -fs /opt/geckodriver /usr/local/bin/geckodriver)

This will install geckodriver v0.14.0 for you. I tested it with the latests firefox 51.0.1

0
user3262242 On

you can append path to the PATH variable at run time as well.

import sys

sys,path.append('the path where the file is stored')