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?

Rachel
  • 1,937
  • 7
  • 31
  • 58
  • 1
    try running sudo pip3 install selenium – santhosh kumar Aug 09 '17 at 07:31
  • Hi @santhoshkumar, thanks for the tip. I tried it out. I am still getting the error :/ – Rachel Aug 09 '17 at 07:34
  • have you tried, webdriver.Firefox() in the python code. The error message shows firefox(small f). Just guessing as a typo. – santhosh kumar Aug 09 '17 at 07:36
  • The error is return when running `from selenium import webdriver`. It's driving me insane :( – Rachel Aug 09 '17 at 07:38
  • 1
    Might be some installation issues, can you try uninstalling the existing selenium modules and install a fresh one using pip3 install selenium – santhosh kumar Aug 09 '17 at 07:39
  • I tried. I am still getting the error – Rachel Aug 09 '17 at 08:01
  • 1
    can you try this sudo pip3 install selenium==3.4.2 and check. – santhosh kumar Aug 09 '17 at 08:09
  • I tried that, too! Still dosn't work somehow. Do I maybe need the Gecko Firefox driver for this? – Rachel Aug 09 '17 at 08:15
  • 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:)- – santhosh kumar Aug 09 '17 at 08:17
  • Hi Santhos, it still won't work. I downloaded Gecko and mentioned it as you suggested. I still get the same error. I edited my question, so you can see, what I do... Any ideas? – Rachel Aug 09 '17 at 08:52
  • 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())` – Tarun Lalwani Aug 09 '17 at 09:10
  • 1
    the executable path should end with the geckodriver(the actual geckodriver and not a folder) – santhosh kumar Aug 09 '17 at 09:42
  • @TarunLalwani thanks, I just did. You can see the result in the original question. Thank you! – Rachel Aug 09 '17 at 09:58
  • 1
    also one more, `ls -alh` in your working directory where the executing python file is – Tarun Lalwani Aug 09 '17 at 10:02
  • @TarunLalwani I did just now and I reported the result in the original qestion. Does that help? – Rachel Aug 09 '17 at 10:17
  • 1
    Only thing i can observer is your Python 2.7 has higher priority in path and your python path are all python 3.5 . Check if you are getting the right version of python being run or not? – Tarun Lalwani Aug 09 '17 at 10:31
  • Yeah, I thought that too. I tried running it with `python3 test.py` and it still returns the same error. I am lost. Entirely. – Rachel Aug 09 '17 at 10:43
  • 1
    Can you check if the default python is 3.5 only. There might be chance, selenium been installed in python3.5 and you are running it through other version in case of multiple versions installed. – SunilThorat Aug 09 '17 at 11:12

1 Answers1

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/')
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • 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? – Rachel Aug 09 '17 at 07:36
  • 1
    and https://stackoverflow.com/questions/31147660/importerror-no-module-named-selenium – Shubham Jain Aug 09 '17 at 07:39
  • 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... – Rachel Aug 09 '17 at 08:03
  • 1
    I think you are missing to add gecko path as below :- binary = FirefoxBinary('path/to/installed firefox binary') – Shubham Jain Aug 09 '17 at 09:11
  • 1
    refer :- https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path/42122284 – Shubham Jain Aug 09 '17 at 09:12
  • Thanks for the effort and help! I tried everything (see my edit in the original question). I still get the error...I am out of ideas.. – Rachel Aug 09 '17 at 09:49