Use Xpath to dynamically locate elements

Xpath provides three very good methods to locate some attribute values ​​for us:

1. contains(a, b) If a contains the string b, it returns true, otherwise it returns false
2. starts-with(a, b) If a starts with the string b, returns true, otherwise it returns false
3. ends-with(a, b) If a ends with the string b, return true, otherwise return false

Insert picture description here
Insert picture description here

The above elements need to be located, as follows:
1) driver.find_element_by_xpath("//[contains(@id,'Uni')]")
select the div node whose id value contains "Uni'"
2) driver.find_element_by_xpath("// div[starts-with(@id,'Uni')]")
select the div node whose id value starts with "Uni'"

Guess you like

Origin blog.csdn.net/Love_Polaris/article/details/108764599