2

I have some trouble with importing selenium webdriver in python. Just to make sure: here is my little script:

import selenium
from selenium import webdriver
browser = webdriver.Firefox(executable_path='/Users/Sleeps/Webdrivers/Firefox/geckodriver')

When I run

from selenium import webdriver,

I am thrown the error

No module named 'selenium.webdriver.firefox.webdriver'.

I neatly follow the steps suggested from Selenium themselves (you can find them here). Nonethelss, I get the error. I have no idea why that is the case. I tried the following:

pip install selenium

python -m pip install -U selenium

sudo pip3 install selenium

No matter what I use, pip confirms

Requirement already satisfied: selenium in ./anaconda/lib/python3.5/site-packages

I further cheked in the Anaconda directory. And I do seem to have the selenium package at the right place: /Users/Sleeps/anaconda/lib/python3.5/selenium/webdriver/__init__.py

EDIT

I further installed the latest gecko driver for MacOS (you can find it here). I unpacked it to Users/Sleeps/Webdrivers/Firefox/.

I ran PATH=$PATH:/Users/Sleeps/Webdrivers/Firefox/geckodriver in the comand line.

Running from pprint import pprint; import os; import sys; pprint(sys.path); pprint(os.getenv("PATH")); pprint(os.getcwd()) returns

['',
 '/Users/Sleeps/anaconda/lib/python3.5/site-packages/six-1.10.0-py3.5.egg',
 '/Users/Sleeps/anaconda/lib/python35.zip',
 '/Users/Sleeps/anaconda/lib/python3.5',
 '/Users/Sleeps/anaconda/lib/python3.5/plat-darwin',
 '/Users/Sleeps/anaconda/lib/python3.5/lib-dynload',
 '/Users/Sleeps/anaconda/lib/python3.5/site-packages',
 '/Users/Sleeps/anaconda/lib/python3.5/site-packages/Sphinx-1.4.1-py3.5.egg',
 '/Users/Sleeps/anaconda/lib/python3.5/site-packages/aeosa',
 '/Users/Sleeps/anaconda/lib/python3.5/site-packages/IPython/extensions',
 '/Users/Sleeps/.ipython']
'/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/Sleeps/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'
('/Users/Sleeps/Dropbox/01_Data '
 'Science/Kooperation/EX/Automobile‘)

ls -alh returns

total 24
drwxr-xr-x@  3 Sleeps  staff   102B  9 Aug 12:06 .
drwxr-xr-x@ 35 Sleeps  staff   1,2K  9 Aug 12:06 ..
-rwxr-xr-x@  1 Sleeps  staff   9,4K  9 Aug 11:59 Test.ipynb

When I run from selenium import webdriver, I still get the error. How can I get rid of it?

18
  • 1
    try running sudo pip3 install selenium Commented Aug 9, 2017 at 7:31
  • 1
    Might be some installation issues, can you try uninstalling the existing selenium modules and install a fresh one using pip3 install selenium Commented Aug 9, 2017 at 7:39
  • 1
    can you try this sudo pip3 install selenium==3.4.2 and check. Commented Aug 9, 2017 at 8:09
  • 1
    Yes Gecko needs to be downloaded and we need to mention the path also like this...browser = webdriver.Firefox(executable_path='/home/santhoshkumar/Softwares/Selenium/drivers/geckodriver'). Hope this works:)- Commented Aug 9, 2017 at 8:17
  • 1
    Add this at top of your code and update the question with the output from pprint import pprint; import os; import sys; pprint(sys.path); pprint(os.getenv("PATH")); pprint(os.getcwd()) Commented Aug 9, 2017 at 9:10

1 Answer 1

1

Try below :-

On Ubuntu/Debian systems, this will install pip (and dependencies) and then install the Selenium Python bindings from PyPI:

$ sudo apt-get install python-pip
$ sudo pip install selenium

After the installation, the following code should work:

#!/usr/bin/env python

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://www.ubuntu.com/')
Sign up to request clarification or add additional context in comments.

6 Comments

Hi @Shubhamjain, I already got pip installed. Running it returns Requirement already satisfied: selenium in ./anaconda/lib/python3.5/site-packages. Any ideas why that is the case?
Thank you for the links! I tried everything out. Even unistalling via pip3 uninstall selenium and installing it again. I am still getting the error...
I think you are missing to add gecko path as below :- binary = FirefoxBinary('path/to/installed firefox binary')
|

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.