Zero Signup ToolsFree browser tools

Developer Tools

XPath Tester

Test XPath 1.0 expressions against XML or HTML documents in your browser. All result types, namespaces, scoped context node, match paths.

Any (auto). The engine picks the best return type for the expression. Default behavior.

Examples (click to use)

Sample documents

783 chars
DOMParser is not defined

XPath 1.0 has no default namespace, so an XML document with xmlns=... needs a prefix to be queried. Common shortcuts (svg, xhtml, xlink, atom, dc, mathml, xsl) work without being declared here.

Quick syntax

  • / root, // any descendant
  • name element by tag, @name attribute by name
  • . current node, .. parent
  • * any element, @* any attribute, node() any node
  • text() text children, comment() comments
  • [1] first match, [last()] last, [position()<3] positional
  • | union, and, or, not(...)
  • contains, starts-with, normalize-space, string-length
  • count(...), sum(...), number(...)
  • Axes: ancestor::, following-sibling::, preceding-sibling::

How to use

  1. Pick the parser that matches your input. XML is strict and reports parse errors; HTML is permissive and recovers from missing tags. Paste your document into the input box on the left.
  2. Type an XPath expression into the field at the top, or click one of the Example pills to try a common pattern. Matches update as you type.
  3. Pick a Result type if you need to override Any: All nodes for scraping, First node for speed, or String, Number, or Boolean to force a primitive return.
  4. If your document uses namespaces (SVG, Atom, XHTML, custom XML), add prefix=uri lines in the Namespaces box so expressions like //svg:circle resolve. Common prefixes (svg, xhtml, xlink, atom, dc, mathml, xsl) work out of the box.
  5. Use the optional Context node field to scope the main expression to a specific element (its own XPath evaluates first and the first hit becomes the start node).
  6. Click Copy path, Copy match, or the Copy all buttons to grab the DevTools-style XPath, the serialized match, or every result at once for use in Selenium, Playwright, Scrapy, or your XSLT stylesheet.

About this tool

XPath Tester evaluates XPath 1.0 expressions against an XML or HTML document using the browser's native DOMParser and document.evaluate APIs. Switch between the strict XML parser (which surfaces parse errors so you can debug a malformed feed or sitemap) and the permissive HTML parser (which recovers from missing tags the same way a browser does, so the expressions you write here match what runs against a real page). Every XPath result type is supported through one select: Any leaves the engine to pick the best return shape; All nodes returns an ordered snapshot of every match (the default for scraping); First node returns the first hit in document order (faster on large documents); String, Number, and Boolean force the result through the matching XPath conversion function. Each matching node renders with its position, node type (element, attribute, text, comment, processing instruction, document, doctype), a DevTools-style 1-indexed XPath path, and a serialized view of its content; copy buttons grab the path, the serialized match, or every match and every path in one click. Namespaces are the trap every XPath user falls into eventually. The namespaces panel takes prefix=uri lines (commented with # if you like) and the engine resolves them against your bindings first, then against the document's own xmlns declarations, then against a built-in shortcut table for svg, xhtml, xlink, atom, dc, mathml, and the XSL family, so the most common cases just work. An optional context node accepts its own XPath, evaluates it against the document, and uses the first match as the starting point for your main query (so axes like child:: or relative paths like ./@id work against a specific scoped element). Useful for building Selenium, Playwright, Puppeteer, and Scrapy selectors before pasting them into a test or a scraper; for debugging XPath inside XSLT and XQuery stylesheets; for testing the //sitemap and //url[loc] paths used to audit XML sitemaps; for extracting fields from RSS or Atom feeds; and for confirming what a DevTools Copy XPath actually selects. Parsing, namespace resolution, and evaluation all happen on your device; the documents you paste never leave the browser.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools