XPath For Selenium
XPath is not the only technology that Selenium supports for locating elements. It also offers an option to search a web element dynamically, which gives you flexibility in how you want to search for elements.
XPath Axis Family Tree Analogy
The major XPath axes follow family tree terminology:
- self:: is you.
Downward:
- child:: are your immediate children.
- descendant:: are your children, and their children, recursively.
- descendant-or-self:: (aka //): are you and your descendants.
Upward:
- parent:: is your mother or father.
- ancestor:: are your parent, and your parent's parent, recursively.
- ancestor-or-self:: are you and your ancestors.
Sideways (consider elements earlier in the document to be younger):
- previous-sibling:: are your younger siblings, in age order.
- following-sibling:: are your older siblings, in age order.
- previous:: are your younger siblings and their descendants, in age order.
- following:: are your older siblings and their descendants, in age order.