Selenium + Python + eclipse configuration in python_win7 x86

Source: Internet
Author: User
Tags selenium python seleniumhq

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.