The furthest distance in the world is probably to see a page element chu there, but I can't locate it!!
There are many ways to locate elements, such as through IDs, name, Class_name, Tag_name, Link_text, and so on, but the limitations of these methods are selenium, and the id attribute, first of all, must not have an id attribute for each element. The id attribute of the second element is not necessarily invariant. So these methods to understand, what we really need to master is through the XPath and CSS positioning, generally as long as the master one can handle most of the positioning work.
Here is a summary of the XPath positioning method, combined with the practice of their own examples to deepen the understanding
First, we need to understand the concept of XPath and basic syntax
Online about the XPath tutorial less, you can look at the Novice tutorial and W3cschool related information:http://www.runoob.com/xpath/xpath-tutorial.html,/http Www.w3school.com.cn/xpath/index.asp
Second, the common XPath localization method
1. Use the attributes within the tag to locate
(1) by id attribute
XPath = "//a[@id = ' start_handle ']"
A indicates that all a elements are selected, plus [@id = ' start_handle '] to select the A element with the id attribute ' Start_handle '
(2) Locating by Name property
XPath = "//input[@name = ' CustName ']"
Summarize : XPath = "//tag name [@ attribute =' property value ']"
Attribute criteria: Most commonly id,name,class, and so on, the category of attributes has no special restrictions, as long as one element can be uniquely identified.
When an attribute is not sufficient to uniquely differentiate an element, you can also take multiple combinations of conditions, as follows:
Xpath= "//input[@type = ' xx ' and @name = ' xx ']"
2. Use the text () method to locate
As shown above, there is a text "back" between the <a></a> tags of the "previous" button, so you can locate them in the following way
XPath = "//a[text () = ' Back ']"
the "Get Started" button can use the following path :xpath = "//a[text () = ' start processing ']"
3. Using the contains () method to locate, also known as fuzzy positioning
XPath = "//Tag name [contains (@ attribute, ' property value ')]"
Take the key information of the href ' basicinfo ', so you can also navigate to the "Get Started" button
Python+selenium Base XPath positioning