Python xpath element positioning method

/html/body/div/div[2]/div[5]/div[1]/div/form/span[2]/input #xpath absolute path
// [@id=“su”] #xpathrelative path
//
[@id=“form”]/span[3]/span[2]/... #Locating the parent element (upper element)
//input[@id=“su”] #Locating input in id=" The element of
"su" //input[@id="su" and @type="submit"] #Use two attributes to locate the element
// [text()='platform login'] #text positioning
//
[.=' Platform login'] #text positioning
//a[contains(text(),"Baidu search")]
#partial text positioning //input[contains(@name,'na')]
#partial attribute positioning //book[price <30] #Locating by text value comparison
//book[1] #Locating by serial number
//book[last()] #Locating the last one
//book[last()-1] #Locating the second to last
//book [position()<=2] #Locating the first and second elements
//book[1]/following-sibling::book[1] #Locating the next element at the same level
//book[2]/preceding -sibling::book[1] #Locate the previous element at the same level
//book[2]/child::title #Locating the child element of the next level
//book[2]/title/... #Locating the parent element of the previous level
//book[2]/title/parent::book #Locating the parent element of the upper level

Guess you like

Origin blog.csdn.net/weixin_44123630/article/details/113815017
Recommended