Guide
Testing XPath expressions against XML and HTML
XPath expressions locate parts of an XML or HTML document: they drive Selenium and Playwright locators, Scrapy and lxml scrapers, XSLT stylesheets and many configuration tools. Writing one blind and running a whole test or crawl to see whether it works is slow. This tester evaluates an expression against a document as you type and shows exactly what it matches.
Paths, steps and predicates
An expression is a path of steps separated by slashes. /catalog/book walks from the root to catalog and then its book children; //book finds book elements anywhere. @id selects an attribute and text() the text nodes. Predicates in square brackets filter a step: //book[@lang="fr"] keeps French books and //book[price > 10] compares a child element’s value as a number. .. steps up to the parent, which CSS selectors cannot do.
Functions and result types
XPath 1.0 has functions for strings (contains, starts-with, normalize-space, substring), numbers (count, sum, round) and booleans (not). An expression can therefore return four kinds of result: a set of nodes, a number, a string or a boolean. Node sets appear as a list of matches; the other three appear as a single value you can copy.
XML and HTML modes
In XML mode the document must be well-formed, and the tool reports the parser’s error if it is not. Element names are case-sensitive. In HTML mode the browser’s forgiving HTML parser builds the tree, adding html, head and body if they are missing and turning every element name into lower case, which mirrors what Selenium or Playwright see in a real page.
Namespaces
Many XML formats, such as RSS with extensions, SVG, sitemaps and SOAP, declare a default namespace with xmlns="…". In XPath 1.0 an unprefixed name never matches an element in a namespace, so //url returns nothing in a sitemap even though the elements are right there. Use //*[local-name()="url"], which matches on the name alone.
A worked example
The Sample is a catalogue of three books. //book[price > 10]/title returns one match, the title “XML Developer’s Guide”, because only that book costs more than 10. sum(//price) returns the number 56.85, and //book[@lang="fr"]/author/text() returns the text node “Corets, Eva”. Each node match is listed with an absolute path such as /catalog/book[1]/title, which tells you exactly where in the document it sits.
Debugging an expression that matches nothing
Shorten the expression until it matches something, then add steps back one at a time. Check the case of element names in XML, check for a default namespace, and remember that //book[2] means the second book within each parent; (//book)[2] is the second in the whole document. Whitespace inside elements also counts: normalize-space(.)="Save" is safer than .="Save" for text comparisons.
What this engine is
Expressions are evaluated by the browser’s own XPath engine through document.evaluate, the same one browser automation tools use in Chrome and Firefox. That makes results a faithful preview for those tools, but it also means XPath 1.0 only: functions from XPath 2.0 and 3.1, such as matches() or ends-with(), are not available.
Related tools
- CSS to XPath converts selectors you already have.
- XML Formatter pretty-prints and validates the document first.
- JSONPath Tester does the same job for JSON documents.
- Regex Tester checks text patterns you combine with XPath.
Checked against the current version of the XPath Tester on .

