Where to find geckodriver needed by Selenium Python package?
I am using Ubuntu 16.04.1 LTS. Executing python -V
returns Python 2.7.12
. I am building a virtualenv off of that so as to install the Selenium package into it via:
pip install -upgrade selenium
But when doing a trial run with the following python script:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/')
it results this error:
Traceback (most recent call last):
File "/home/myuser/bin/selenium-experiment.py", line 2, in <module>
browser = webdriver.Firefox()
File "/home/myuser/python_virtualenv/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/home/myuser/python_virtualenv/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.
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7f782c1caa50>> ignored
Since geckodriver
is an executable, I concluded that it should be provided by the installation of the selenium package via pip
or at least error out with some message stating what I need to do next. Apparently not, so I dug further: I thought that perhaps Ubuntu should have a package that provides the geckodriver
executable so I used apt-file search geckodriver
to search for it and found no results.
Where do I get this geckodriver
executable?
Find the latest release for your OS.
Extract it, and copy geckodriver to /usr/local/bin
-- so if v0.11.1
was the most recent version, and you were on 64bit linux, you'd do this:
export GECKO_DRIVER_VERSION='v0.24.0'
wget https://github.com/mozilla/geckodriver/releases/download/$GECKO_DRIVER_VERSION/geckodriver-$GECKO_DRIVER_VERSION-linux64.tar.gz
tar -xvzf geckodriver-$GECKO_DRIVER_VERSION-linux64.tar.gz
rm geckodriver-$GECKO_DRIVER_VERSION-linux64.tar.gz
chmod +x geckodriver
cp geckodriver /usr/local/bin/
Now your trial run should work.
Ubuntu 16.04+:
sudo apt-get install firefox-geckodriver