Python+selenium positioning elements

Source: Internet
Author: User

I. Installing Python
1. Configure the environment variable c:\python27;c:\python27\scripts
2. Verify that the Pyton is available and enter Python in cmd without error.

Two. Installing the Selenium Library
4. Install selenium; in cmd, enter: Pip install Selenium

Three. The positioning methods corresponding to the Webdriver are:

    • Driver.find_element_by_name ()--most commonly used, simple
    • DRIVER.FIND_ELEMENT_BY_ID ()--most commonly used, simple
    • Driver.find_element_by_link_text ()--positioning text connection is useful
    • Driver.find_element_by_xpath ()--the most flexible, versatile
    • Driver.find_element_by_css_selector ()

Four. Friebug

1. Open the Firebug plugin of Firefox browser, click the mouse arrow in the top left corner of the plugin, then click on the element on the page, the HTML tab of the Firebug plugin will see the page code, the mouse moves to the element's label click. For example, we click on the Baidu home page "Baidu click" button:

From Firepath, you can see properties such as the Id,tag,class of the element.

    • Chrome developer Tools (F12)

Open the Chrome browser and press F12 on the keyboard to open the developer tools. You can get the same results as Firepath from the developer tools:

ID and name Locator

This is a simple and efficient method. For example, the method of positioning Baidu Home text box, we can use the ID to locate (the element provides an id attribute, you can uniquely navigate to it):

To locate the "settings" link in the top right corner of the Baidu home page, we can use name to locate (the element provides the Name property and can uniquely navigate to it):

by Linx text location:

XPath positioning

CSS Positioning

Python+selenium positioning elements

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.