Python-xpath Positioning Method Detailed

Source: Internet
Author: User
Tags logical operators xpath

First, XPath basic positioning usage

1.1 Using ID to locate--driver.find_element_by_xpath ('//input[@id = "kw"])

  

1.2 Using class positioning-driver.find_element_by_xpath ('//input[@class = "S_ipt"]

  

1.3 Of course, through the usual 8 ways of combining XPath can be located (name, Tag_name, Link_text, Partial_link_text) above only listed 2 common ways OH.

Second, XPath relative path/absolute path location

2.1 Relative positioning-Starting with//://form//input[@name = "Phone"]

  

2.2 Absolute positioning-with/start, but to start from the root directory, more cumbersome, generally not recommended to use such as:/html/body/div/a

  

XPath text, fuzzy, logical positioning

3.1 "Text positioning" uses the text content of the text () element such as://button[text () = "Login"]

  

3.2 "Fuzzy positioning" using contains () contains functions such as://button[contains (Text (), "login"),//button[contains (@class, "btn")]

  

3.3 "Fuzzy positioning" uses starts-with-match attribute values starting with XX, ends-with-matches attribute values ending with xx such as://button[starts-with (@class, "btn"),//input[ Ends-with (@class, "-special")]

3.4 Using logical operators--and, or, for example://input[@name = "Phone" and @datatype = "M"]

Four, XPath axis positioning

 4.1-axis operation

 Ancestor: Ancestor nodes include parent
Parent: Father Node
Prceding-sibling: All sibling nodes before the current element node label
Prceding: All nodes before the current element node label following-sibling: All sibling nodes after the current element node label following: All nodes after the current element node label use syntax: Axis name:: node name uses more scenes: page display Data columns shown as a table style are as follows:

  

Attention:

#定位 find the element--to be uniquely identified
#优先使用id
#舍弃: The presence of subscripts, the presence of absolute positioning, and the abandonment of dynamic ID changes

Python-xpath Positioning Method Detailed

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.