XPath is a syntax for selecting elements and context from XML documents. It works really well on HTML, and similarly to CSS selectors.
Examples
//elementName[contains(@attribute, 'Some Value')]
//elementName[contains(text(), 'Some Text')]
//a[contains(@id='my-link')]
- https://www.w3schools.com/xml/xpath_axes.asp
- https://stackoverflow.com/questions/28237694/xpath-get-parent-node-from-child-node
Index of elements begins at 1
, instead of 0
Select 2nd element
//*[contains(@attribute, 'Some Value')][2]
Add /parent::elementName
to the end of the selector
//elementName[contains(@attribute, 'Some Value')]/parent::parentElementName
//*[contains(@attribute, 'Some Value')]/parent::*