XPath positioning of Selenium+python automation

Source: Internet
Author: User
Tags xpath

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 portion of an XML( a subset of standard generic Markup Language ) documents. 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

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 Properties

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 more accurate point

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

Four, XPath: level

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

Five, XPath: Index

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

2. Although it is difficult to identify the twins, they are born in succession and can be located at the rank of the family.

3. like triplets Brothers

4. use XPath to position the boss, Dick, and Old Three (the index is calculated from 1 , not the same as the Python index)

Six, XPath: Logical Operations

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

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

Seven, XPath: Fuzzy Matching

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

2. mastered the fuzzy matching function, basically not in place

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 positioning of Selenium+python automation

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.