XPath Tester
Test XPath 1.0 expressions against XML or HTML and see matching nodes, attributes, text and numeric or string results instantly, using the browser's engine.
What is XPath Tester?
The XPath tester evaluates an XPath expression against an XML or HTML document you paste and shows the result: matching elements with their markup and text, attribute values, or a number, string or boolean for expressions such as count() or sum(). Results update as you type.
How to use XPath Tester
- Enter an XPath expression, e.g.
//book[price > 35]/title. - Choose whether to parse the document as XML or HTML.
- Paste or edit the document.
- Read the number of matches and each matched node, or the scalar result.
Example
//book[price > 35]/title on the sample bookstore XML
2 matches: Learning XML, XQuery Kick Start
sum(//book/price) returns 119.94.
When to use XPath Tester
Use it to develop XPath for web scraping, Selenium/Playwright locators, XSLT or XML configuration processing. Browsers implement XPath 1.0 only, so XPath 2.0/3.1 functions (e.g. matches(), string-join()) are not available. Scripts in pasted HTML are not executed.
How XPath Tester works
The document is parsed with the browser's DOMParser (application/xml or text/html); XML syntax errors are reported. The expression is evaluated with document.evaluate() – the browser's native XPath 1.0 engine – using ANY_TYPE results, so node-sets, numbers, strings and booleans are all supported. Namespace prefixes are resolved from the declarations on the root element. Up to 200 matches are displayed.
Common Use Cases
- Build a locator like
//button[normalize-space()="Save"]for UI tests. - Extract all attribute values with
//book/@category. - Count or sum values in an XML feed.
- Debug why an XPath in a scraper returns nothing.
FAQs
Why does my XPath with a default namespace return nothing?
In XPath 1.0 unprefixed names never match namespaced elements. Declare a prefix on the root element and use it, or use *[local-name()='book'].
Should I parse as HTML or XML?
Use HTML for web pages (tolerant parsing, lowercase tag names); use XML for feeds, SOAP, sitemaps and configs.
Is XPath 2.0 supported?
No. All major browsers only implement XPath 1.0.