How to use the XPath Tester
- Paste XML or HTML (switch the mode for HTML pages), or load the sample.
- Type an XPath expression — results update as you type.
- Each match shows its exact path, attributes and content; click a path to use it as the expression.
- Try the example chips to learn common patterns.
XPath in a nutshell
| Expression | Selects |
|---|---|
/catalog/book | book elements that are direct children of the root catalog |
//title | every title element anywhere |
//book[@id='bk102'] | books whose id attribute equals bk102 |
//book[price > 30]/title | titles of books priced above 30 |
//book[1] / //book[last()] | the first / last book in each parent |
//a[contains(@href, 'docs')] | links whose URL contains “docs” |
//li[normalize-space()='Home'] | list items whose trimmed text is exactly Home |
count(//book) | a number instead of nodes |
//title/text() | the text nodes themselves |
Namespaces
In XML with a default namespace (xmlns="…"), //book matches nothing because the elements are in that namespace. Declared prefixes are picked up automatically, and the default namespace is available as the prefix d: — write //d:book. Alternatively use //*[local-name()='book'].
HTML mode
HTML is parsed the way a browser parses it, so missing closing tags are repaired and a <tbody> is inserted into tables — the same structure Selenium, Playwright and scrapers see. The browser’s built-in XPath 1.0 engine is used. Tidy documents first with the XML formatter, or convert them with XML to JSON.
Tools that pair well with the XPath Tester
- JSONPath Tester — Type a JSONPath query and instantly see what it selects — with the exact path of each match.
- Regex Tester — Type a pattern and watch matches highlight live in your test text.
- Online HTML Editor — A lightweight code playground: edit HTML, CSS and JavaScript side by side, see the result instantly, read console output and download your page as one HTML file.
- HTML Formatter — Paste minified or messy markup and get clean, consistently indented HTML — including embedded <style> and <script> blocks.
Frequently asked questions
Which XPath version is supported?
matches() or upper-case() are not available.Why does my XPath work in the browser but not in my scraper?
tbody) and pages often change with JavaScript. Test against the raw HTML your scraper downloads, using HTML mode here.