Common XPath Methods With Examples

Eugene Truuts
4 min readSep 3, 2023

This tutorial will clarify various methods for selecting elements and data within XML or HTML documents. I’ve included for you the explanations and examples of standard XPath methods.

Node Selection

Node selection in XPath refers to choosing specific elements, attributes, or nodes within an XML or HTML document based on their type or location in the document’s hierarchy.

//img
Select all image elements on a page

Attribute Selection

Attribute selection in XPath involves choosing elements within an XML or HTML document based on their attributes’ values.

//*[@id = 'gridItemRoot']
Select all Bestseller elements in a grid with the attribute id set to “gridItemRoot.”

Predicate Filtering

Predicate filtering in XPath applies conditions or filters to select specific elements or nodes based on certain criteria. Use conditions inside square brackets to filter elements.

//span[contains(@class, 'sc-price') and number(translate(., '$', '')) < 10.00]

--

--

Eugene Truuts
Eugene Truuts

Written by Eugene Truuts

🇪🇪🇺🇸SDET at RingCentral, Inc. 👨🏻‍🎓B.Sc. in Computer Science. Talks about testing, automation, Playwright framework, JavaScript, GitLab, productivity,

No responses yet