Selenium2+python Automated 7-xpath Positioning

Source: Internet
Author: User
Tags xpath

Objective

In a simple introduction of the tool to view the target element of the XPath address, tools to view the more rigid, not flexible, and sometimes the direct copy paste will not be located. This time you need to manually write the XPath, this is a detailed explanation of the XPath syntax.

What is XPath?

Official Description: XPath is the XML Path language, which is a language used to determine the location of a part of a document in XML1 (a subset of standard Universal Markup Language 3). Anyway small to see this introduction is Foggy, the popular point is to find this element through the path of the element, equivalent to locating an object's coordinates, to find this object.

First, XPath: attribute positioning

    1. Xptah can also be positioned through the attributes of the element ID, name, class, as

2. You can then use the following XPath method to locate

Second, XPath: other attributes

1. If an element ID, name, and class attribute are not available, you can also navigate to the


Third, XPath: label

1. Sometimes the same property, the same name is more, this time can be filtered by the label, positioning a bit more accurate

2. If you do not want to create a label name, you can use the * number to indicate any label

3. If you want to make a specific label, you can write the label name directly

Iv. XPath: Hierarchy

1. If an element, its properties are not very obvious, can not directly navigate to, this time we could first find it Dad (parent element)

2. After finding his dad, we'll find the next level.

3. As shown, to locate the input tag, it's dad's id=s_kw_wrap.

4. If his father's attributes are not obvious, look for it, Grandpa Id=form.

5. You can then navigate through the hierarchical relationship to

V. XPath: index

? 1. If an element whose sibling element is the same as its label, it cannot be positioned at this time by hierarchy. Because it was a father-born, multi-fetal brother.

2. Although it is difficult to identify the twins, the birth is sequential, so it can be positioned at the rank of the family.

? 3. such as Triplets Brothers

? 4. Use XPath to position the eldest, second, and old three (where the index is calculated from 1, not the same as the Python index)

Vi. XPath: logical operation

? 1.xpath There is also a relatively strong function, can be multiple attribute logical operation, can be supported with (and), or (or), non (not)

? 2. The more commonly used is the and operation, while satisfying two properties

Vii. XPath: Fuzzy matching

? 1.xpath also has a very powerful feature, fuzzy matching

? 2. Mastered the fuzzy matching function, basically there is no location

? 3. For example, I want to locate the HYPERLINK "hao123" of Baidu Page, said in the previous article can pass By_link, also can through By_partial_link, fuzzy match locates to. Of course, XPath can also have the same function and be more powerful.

XPath can be thought of as an element in the location of the Dragon Slayer Knife. Martial Arts Supreme, Blades xpath,css not out, who with the battle? The next lesson will be illuminated by the reclining sword CSS positioning.

Selenium2+python Automated 7-xpath Positioning

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.