简体   繁体   中英

Selenium WebDriver python bindings

I can't make python bindings for webdriver workable. Here is tutorial for installing.

 easy_install webdriver 

Won't find webdriver package so I have to install it manually from sources. I've downloaded source from trunk, set WEBDRIVER and PYTHONPATH variables and installed webdriver:

   ~$ cd ~
   ~$ svn checkout http://selenium.googlecode.com/svn/trunk/ selenium-read-only
   ~$ cd selenium-read-only
   ~# python setup.py install
   ~$ env |grep PYT
   ~$> PYTHONPATH=:/home/ockonal/selenium-read-only/../../../firefox/lib-src:/home/ockonal/selenium-read-only/..
   ~$ env |grep WEB
   ~$> WEBDRIVER=/home/ockonal/selenium-read-only

Here is output of setup.py script.

Then I downloaded RemoteDriverServer.jar and ran it:

 java -jar RemoteDriverServer.jar 8888 

Now I want to include webdriver module in python script:

from selenium.firefox.webdriver import WebDriver

ImportError: No module named firefox.webdriver

最新的selenium(包括webdriver)绑定应该是pip可安装的:

pip install selenium

Try this.

I'm guessing that selenium was installed to:

/usr/local/lib/python2.6/

In either the site-packages or dist-packages folder.

Since the link to your setup.py output is broken I can't see the results so I'm going to make some assumptions based on a 'normal' setup.py install

One of these folders should exist:

/usr/local/lib/python2.6/dist-packages/selenium/firefox/

or

/usr/local/lib/python2.6/site-packages/selenium/firefox/

This is the folder where the python library should exist based on the setup.py how the packages are defined in setup.py.

Now go back to the folder where you downloaded the source and navigate to.

./firefox/source/py/

Copy the all of the source files to whichever one of these two files exist.

/usr/local/lib/python2.6/dist-packages/selenium/firefox/

or

/usr/local/lib/python2.6/site-packages/selenium/firefox/

This is the equivalent to a 'manual install'. Although I'm not sure why you'd need to because the firefox parts of the package are clearly specified in the setup.py source.

...

'selenium.firefox': 'firefox/src/py',
...

If there is nothing for selenium under the site-packages or dist-packages folders the 'setup.py install' may not have installed correctly because it didn't have the required permissions.

Be sure to run 'setup.py install' with sudo if you haven't already. Since, root permissions are necessary to modify/add anything under '/usr'.

You need copy build/webdriver-extension.zip to your python installation folder. Just copy the build/webdriver-extension.zip to /usr/lib/pythonX.X/site-packages/selenium-2.0_dev-py2.6.egg/selenium/firefox . It's an extension that you manually install.

sudo pip install selenium 

failed for me on Ubuntu 10.04

sudo pip install -U selenium

worked

I had the same problem and I came to a different solution. Trying to run selenium in Python 3 which I installed via homebrew , and selenium installed via pip3 . Got the same error of "ImportError: No module named 'selenium'". Checked my path using:

import sys
print(sys.path) 

and found that where selenium was installed was indeed in this list ( /usr/local/lib/Python3.4/site-packages ).

However, I had downloaded the binary and so the folder named selenium was within the wrapper folder of selenium-2.45 . Although perhaps not the greatest solution, I was able to get selenium running by copying the internal selenium folder to the same level as the selenium-2.45 folder.

I don't think that this is a final solution, as it goes around the setup script, but for now, it seems to work just fine, and I am able to use the selenium module and its contents (so far).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM