1. First configure the eclipse + pydev Environment
A) install JDK
B) install eclipse
C) install python2.7 and install pydev.
2. Go to the official website (http://seleniumhq.org/download/) to download the selenium Python File
Click Download of python to go To the download page of selenium python, https://pypi.python.org/pypi/selenium
3.download selenium-2.35.0.tar.gz, decompress it, and run the python setup. py install command.
Or run the command: Pip install-u selenium install selenium under directory c: \ python27 \ scripts, but you need to install the setuptools-py27 first (https://pypi.python.org/pypi/setuptools/1.0)
4. chromedriverhttps: // code.google.com/p/chromedriver/downloads/detail? Name1_chromedriver_win32_2.2.zip & can = 2 & Q =, decompress chromedriver to the C: \ python27 directory (the latest version is required for chromedriver)
5. Run the test script:
From selenium import WebDriver
From selenium. Common. Exceptions import nosuchelementexception
From selenium. WebDriver. Common. Keys import keys
Import time
Browser = WebDriver. Chrome () # Get local session of Firefox
Browser. Get ("http://www.baidu.com") # Load page
Assert "Yahoo! "In browser. Title
ELEM = browser. find_element_by_name ("p") # Find the query box
ELEM. send_keys ("seleniumhq" + keys. Return)
Time. Sleep (0.2) # Let the page load, will be added to the API
Try:
Browser. find_element_by_xpath ("// A [contains (@ href, 'HTTP: // seleniumhq.org ')]")
Except t nosuchelementexception:
Assert 0, "can't find seleniumhq"
Browser. Close ()
7. Solution to ie failure
The problem is as follows: (I use Python)
Webdriverexception: Message: u'unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones .'
Later I checked some information and found two solutions:
1) modify the security policy of IE, as prompted in exception.
2) run the following code before generating a WebDriver object:
1 From selenium. WebDriver. Common. desired_capabilities import desiredcapabilities
2 desiredcapabilities. internetexplorer ['ignoreprotectedmodesetting'] = true