- Home
- Tools
- Text & Code
- XPath Tester
XPath Tester
Evaluate XPath 1.0 expressions against XML or HTML with highlighted matches, node paths, and formatting.
Ctrl+Enter to evaluate immediately
Local only · 5 MiB limit0 chars
XML parsed strictly — must be well-formed. XPath 1.0 · browser-native.
Results
No result yet
Enter XML or HTML and an XPath expression, or load the sample. Click a result to highlight its source line. Use arrow keys to navigate matches.
Working notes
Use XPath Tester with the boundary visible.
XPath Tester evaluates XPath 1.0 expressions against XML or HTML documents, highlighting matching nodes and displaying their full paths — all locally in your browser.
What is XPath Tester?
XPath (XML Path Language) is a query language for selecting nodes from an XML or HTML document. It uses path expressions to navigate elements, attributes, text, and other node types, similar to how file system paths navigate directories. XPath 1.0 is natively supported by every modern browser through the DOM Level 3 XPath API, which means queries execute locally without any server processing. XPath is used extensively in XSLT transformations, XML Schema validation, web scraping (with tools like Scrapy and lxml), automated testing (Selenium locators), and configuration parsing. Common expressions include element selection (//book), attribute predicates (//book[@category="fiction"]), positional filters (//item[1]), and functions like contains(), count(), and string-length(). This tool parses the input with DOMParser in strict XML or lenient HTML mode, evaluates the expression with document.evaluate(), and presents the results with highlighted source lines, full node paths, and value previews. You can also format the input for readability and copy results with one click.
When to use it
- Debugging XSLT stylesheets — test individual location paths against a source document to verify they select the intended node set.
- Writing Selenium locators — prototype XPath selectors against real HTML pages for automated UI tests before embedding them in test code.
- Exploring XML APIs — navigate unfamiliar SOAP or REST-XML responses by querying for specific elements, attributes, or text nodes.
- Scraping HTML content — test XPath expressions against an HTML page to confirm they extract the intended elements before running a scraping pipeline.
- Learning XPath syntax — experiment with axes (child, descendant, ancestor, following-sibling), predicates, and functions interactively against XML or HTML.
How to use it
- 01Select XML or HTML mode depending on your input format. HTML mode is lenient and handles unclosed tags; XML mode requires well-formed markup.
- 02Paste the document into the input area, or load a sample. Use the Format button to beautify the input for readability.
- 03Enter an XPath expression such as //element, /root/child[@attr], or count(//item). Evaluation runs live after a short pause.
- 04View highlighted matches in the source, or inspect scalar results (string, number, boolean) for aggregate expressions. Copy input or results with the Copy button.
Common mistakes
- Forgetting the double slash — //book searches the entire document, while /book only matches a root-level <book> element.
- Case sensitivity in HTML mode — HTML elements are uppercased in the DOM, so use //BODY or //DIV, or use the translate() function for case-insensitive matching.
- Confusing XPath 1.0 with 2.0+ — browser-native evaluation supports XPath 1.0 only. Functions like matches(), lower-case(), and if/then/else are XPath 2.0+ and will cause errors here.
- Using text content without text() — //title returns element nodes; //title/text() returns their text node children. The distinction matters when extracting values.
- Predicate indexing starts at 1 — //item[0] never matches; the first item is //item[1].
Synthetic example
Select fiction titles
Input
//book[@category="fiction"]/title
Result
<title lang="en">The Great Gatsby</title> <title lang="en">1984</title>
Related standards
Limits and data boundary
- Only XPath 1.0 is supported — the browser does not implement XPath 2.0+ features like regular expressions, conditional expressions, or sequence types.
- Namespace handling depends on the document — elements in a default namespace may require an explicit prefix or custom resolver.
- In HTML mode, element names are uppercased in the DOM (e.g., //DIV not //div) because the browser normalizes HTML tag names.
- Results are limited to 1,000 matching nodes to keep the UI responsive on large documents.
Frequently asked questions
- Which version of XPath does this tool support?
- XPath 1.0, evaluated natively by the browser DOM API. XPath 2.0+ functions and syntax are not available.
- Is my data uploaded to a server?
- No. The document is parsed and the XPath expression is evaluated entirely in your browser. Nothing is sent over the network.
- Can I use this with HTML?
- Yes. Switch to HTML mode for lenient parsing that handles unclosed tags and missing quotes automatically. Note that HTML element names are uppercased in the DOM, so use //DIV instead of //div in your expressions.
- Why does my expression return no results?
- Common causes: in HTML mode, element names must be uppercase (//DIV not //div); in XML mode, namespaces may require a prefix or local-name() predicate; tag names are case-sensitive; or the expression uses XPath 2.0+ syntax not supported by the browser.
Keep working