XPath Tester
Test XPath expressions against XML documents — see matched nodes instantly
XPath Tester
Test XPath expressions against XML documents — see matched nodes instantly
Features
- Evaluate XPath 1.0 expressions against pasted XML or HTML using `document.evaluate()`
- Native browser XPath engine — same one the developer console uses
- Result types: node sets (snapshot), boolean, number, string — picked automatically
- Common operators supported: child/descendant axes, predicates, function calls (count, contains, …)
- Useful for testing XPaths before using them in scrapers, XSLT, or test selectors
How to use
- Paste your XML document in the left panel.
- Enter an XPath expression in the input field.
- Click Evaluate or press Enter to see results.
- Copy matched nodes using the Copy button.
Tips & Best Practices
- XPath 1.0 is what browsers implement. XPath 2.0/3.0 (with lookup syntax, regex matching, etc.) needs a separate engine like Saxon.
- For HTML input the parser is lenient; for strict XML use the `<?xml` declaration at the top to enable XML mode.
- Namespace handling in XML: declare a namespace resolver function in production code; the tester uses default namespace inference.
- For CSS-style selection in browser tests, prefer querySelectorAll over XPath; XPath shines for tree-walking with axes (`parent::`, `following::`).
- For scraping: XPath is more powerful than CSS but slower; pick the right tool for the structure of the page.
FAQ
What is XPath?
XPath (XML Path Language) is a query language for selecting nodes from XML documents. It uses path expressions to navigate elements, attributes, and text.
What XPath functions are supported?
All standard XPath 1.0 functions are supported, including text(), contains(), starts-with(), position(), count(), and more.
Is my data private?
Yes, all evaluation happens in your browser using the native DOMParser and XPath APIs. No XML data is sent to any server.
What XPath version does this support?
The tester uses your browser's native XPath engine, which implements XPath 1.0 — the version supported by the DOM. XPath 2.0/3.1 features (let bindings, sequences, regex functions) are not available because no major browser ships them.
Can I use XPath on HTML documents?
Yes, paste HTML and the parser will treat it as XML-style markup. Because HTML is case-insensitive but XPath is case-sensitive, prefer lowercase element names in your expressions (e.g., //div instead of //DIV).
How do I select elements by attribute or class?
Use predicates with the @ prefix: //a[@href] selects all links with href, //div[@class="hero"] matches a specific class. For elements with multiple classes, use contains: //div[contains(@class, "hero")].
How does XPath compare to CSS selectors?
CSS selectors are simpler and faster for common cases (descendants, classes, IDs), while XPath is more powerful for navigating up the tree, matching by text content, or using positional logic. Many testing frameworks (Playwright, Selenium) accept both — use XPath when CSS falls short.