Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 810 Bytes

xpath.md

File metadata and controls

34 lines (23 loc) · 810 Bytes

XPath

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')]

XPath Axes

Select Nth of selection

Index of elements begins at 1, instead of 0

Select 2nd element
//*[contains(@attribute, 'Some Value')][2]

Parent Element

Add /parent::elementName to the end of the selector

//elementName[contains(@attribute, 'Some Value')]/parent::parentElementName
//*[contains(@attribute, 'Some Value')]/parent::*