trouble importing webdriver right at the beginning

4,128 views
Skip to first unread message

Steve

unread,
Dec 8, 2013, 2:57:39 PM12/8/13
to obey-the-test...@googlegroups.com
Howdy, I'm not totally new to Python but I am new to Python 3.  I'm starting to work through the book but having trouble just getting the pre-reqs set up properly (apparently).  

I've used pip-3.3 to install Selenium but when I try the very first "functional_tests.py" script on page 3 I can't import webdriver, I get the error "ImportError: cannot import name webdriver".  I've made sure selenium and webdriver are in the right place 
/usr/lib/python3.3/site-packages/selenium/webdriver/

and that python has the proper path
>>> sys.path
['', '/usr/lib/python3.3/site-packages/setuptools-2.0-py3.3.egg', '/usr/lib64/python33.zip', '/usr/lib64/python3.3', '/usr/lib64/python3.3/plat-linux', '/usr/lib64/python3.3/lib-dynload', '/usr/lib64/python3.3/site-packages', '/usr/lib/python3.3/site-packages']

and that there is only one copy of Selenium on the system
[root@localhost steve]# updatedb
[root@localhost steve]# locate selenium.py
/usr/lib/python3.3/site-packages/selenium/selenium.py

I CAN import selenium and it is where I expect it:
>>> import selenium
>>> selenium.__path__
['/usr/lib/python3.3/site-packages/selenium']

but not webdriver (starting over in a fresh invocation of python).

>>> from selenium import webdriver
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name webdriver

My googling attempts have not yielded anything helpful, other than warnings that Python3 does handle relative imports differently than Python2, but nothing I've followed  up on with that seems appropriate.  Does anyone have any suggestions or ideas?  Thanks.

Zakatell Kanda

unread,
Dec 8, 2013, 7:51:16 PM12/8/13
to obey-the-test...@googlegroups.com
Hi steve, try this on a virtualenv, not your global python3 package, I see no reason you cannot import it though, try to re-install selenium?

Harry Percival

unread,
Dec 9, 2013, 2:51:22 AM12/9/13
to obey-the-test...@googlegroups.com
That is very weird, isn't it? It sounds like the version of Selenium you have is corrupted in some way.

What version is it?

    pip-3.3 freeze
    pip-3.3 freeze | grep selenium

I wonder if the latest version of selenium has a bug on Python 3?    When I tried installing it just now, the latest version (2.38.1) had some bugs:

      File "/home/harry/.virtualenvs/testsel/lib/python3.3/site-packages/selenium/webdriver/firefox/firefox_profile.py", line 226
        print "(skipping) failed to json.loads existing prefernce:", matches.group(1), matches.group(2)



>>> from selenium import webdriver
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/harry/.virtualenvs/testsel/lib/python3.3/site-packages/selenium/webdriver/__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox
  File "/home/harry/.virtualenvs/testsel/lib/python3.3/site-packages/selenium/webdriver/firefox/webdriver.py", line 26, in <module>
    from selenium.webdriver.firefox.extension_connection import ExtensionConnection
  File "/home/harry/.virtualenvs/testsel/lib/python3.3/site-packages/selenium/webdriver/firefox/extension_connection.py", line 22, in <module>
    from selenium.webdriver.remote.remote_connection import RemoteConnection
  File "/home/harry/.virtualenvs/testsel/lib/python3.3/site-packages/selenium/webdriver/remote/remote_connection.py", line 21, in <module>
    import httplib
ImportError: No module named 'httplib'

Version 2.37 does work. Try uninstalling and reinstalling that version:

    pip-3.3 uninstall selenium
    pip-3.3 install selenium==2.37

Does that work?  I'll report a bug in the meantime...
 


--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
------------------------------
Harry J.W. Percival
------------------------------
Twitter: @hjwp
Mobile:  +44 (0) 78877 02511
Skype:         harry.percival

Harry Percival

unread,
Dec 9, 2013, 2:57:49 AM12/9/13
to obey-the-test...@googlegroups.com
Sure enough, there's a similar, but not identical issue on the selenium developers mailing list.  They recommend installing 2.37.2 temporarily, and a fix will be out later in the week...

https://groups.google.com/forum/#!topic/selenium-developers/F9Mwmf5uszA

    pip-3.3 uninstall selenium
    pip-3.3 install selenium==2.37.2

Steve

unread,
Dec 9, 2013, 11:17:00 AM12/9/13
to obey-the-test...@googlegroups.com, hj...@cantab.net
That did it, thank you!  Funny, I assumed the problem was on the Python side, either in my understanding or in my install, it didn't occur to me to look on the Selenium side.  I did remove and reinstall Selenium, but of course I just got the same version.

@Zakatell, thanks for the suggestion.  I haven't used virtualenv because I do all my testing work in individual virtual machine snapshots.  I assumed its advantage was in custom environments for each project but I can see how it would help prevent pathing problem with system packages too.  I'll check it out.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-goat-book+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
--
------------------------------
Harry J.W. Percival
------------------------------
Twitter: @hjwp
Mobile:  +44 (0) 78877 02511
Skype:         harry.percival
Reply all
Reply to author
Forward
0 new messages