3

I am trying to install Selenium WebDriver with Python on my Mac. I used this command:

sudo easy_install selenium

After that, I tried the following simple test:

python

from selenium import webdriver
driver = webdriver.Firefox()

And I got the following error. What am I doing wrong?

Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/selenium-3.0.0.b3-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 68, in init self.service.start() File "/Library/Python/2.7/site-packages/selenium-3.0.0.b3-py2.7.egg/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.

0

2 Answers 2

1

If you call a selenium driver without any arguments, the path to the webdriver executable must be in the system PATH environment variables.

Alternatively, you can specify the path explicitly as such:

driver = webdriver.Firefox("path/to/the/FireFoxExecutable")
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! How do find out path/to/the/FireFoxExecutable on my mac?
this answer tells how to add the browser binary location, not geckodriver's location... so it does not answer the OP's question
0

The error is telling you that it can't find geckodriver. geckodriver is an additional component that you must install to control Firefox. It's not included with the selenium package, so it must be installed separately.

The following shell script will download the latest geckodriver from Mozilla's repo and place it in usr/local/bin, so it can be found on your PATH:

#!/bin/sh
url=$(curl -s "https://api.github.com/repos/mozilla/geckodriver/releases/latest" | python -c "import sys, json; r = json.load(sys.stdin); print [a for a in r['assets'] if 'linux64' in a['name']][0]['browser_download_url'];")
curl -L -o geckodriver.tar.gz $url
tar -xzf geckodriver.tar.gz
chmod +x geckodriver
sudo mv geckodriver /usr/local/bin

(run this script after you install selenium via pip or easy_install)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.