Xpath positioning the python selenium

  Attribute Description

  XPath syntax description support node, the node is described as a logical expression is true or false, any node can determine the genuineness expression in square brackets indicates that this condition must XPath processing before the first node is satisfied. In a step description of how many may have no limit.

  For page elements, can be used XPath expressed as HTML attribute values to locate the tag to Baidu home page, for example, view the following several XPath notation:

 

XPath1: //*[@id="su"]
XPath2: // input [@ value = "Baidu,"]
XPath3: //input[@class="bg s_btn"]

 

 

 

       XPath1 , 2 , 3 are in fact represented " Baidu, " the button element, just select a different attribute values only. XPath1 expressed find id is "su" elements; XPath2 expressed find value as " Baidu, " the input tag element; and XPath3 said looking class that is the style called "bg s_btn" the input tag element.
 

  This explains the beginning of what I call XPath with taking the above mentioned id , CSS , the Name practice, etc., and can be understood as taking HTML tag attributes nothing, and the more flexible way, and do a variety of multi-layered match as monosubstituted CSS is "test" , will remove all CSS to "test" the elements, and if written in XPath manner as // input [@ class = "test "], it is removed CSS to "test" and only input element; if upper understood id , as // div [@ id = "Test"] // * [@ class = "Test"] , is then positioned id is "test" div all class of "test" element. There are even more flexible way of fuzzy matching, should the XPath for the// a [contains (text () , ' new ')] , as represented by all contain " new " in this text a element, such as " news " a tag will be positioned out.

  Notes: 1. The beginning of the two slashes ( // ) represents a relative path; 2. using wildcard * indicates matches any

  Sometimes a plurality of positioning elements that need to select a group of elements to meet the requirements set, the XPath use is quite convenient, for example:

 XPath4: //a[@class="mnav"]
 XPath5: //a[@class="mnav"][2]

 

 

Level positioning

  

Guess you like

Origin www.cnblogs.com/Mr-ZY/p/11696574.html