One article mentions xpath element locating, but some of the articles cannot adapt to special and personalized scenarios. In this article, we provide the ultimate article on the positioning of xpath elements. You can find the solutions you need here.
Method 1: positioning through absolute paths (I believe you will not use this method)
By. xpath ("html/body/div/form/input ")
Method 2: locate through relative paths (the most commonly used method)
By. xpath ("// input ")
Method 3: locate by element index
By. xpath ("// input [4]")
Method 4: Use the xpath attribute to locate (which can be used in combination with the methods in 2nd and 3rd)
By. xpath ("// input [@ id = 'kw1']")
By. xpath ("// input [@ type = 'name' and @ name = 'kw1']")
Method 5: use partial property value matching (the most powerful method)
By. xpath ("// input [start-with (@ id, 'Nice ')
By. xpath ("// input [ends-with (@ id, 'Beautiful ')
By. xpath ("// input [contains (@ id, 'So Beautiful ')]")
6th methods: Use the xpath axis (not used)
I hope these methods will help you.
Selenium positioning using Xpath