1. Home
  2. Developer tools
  3. XPath Tester

XPath Tester

Check a scraper or test selector before you put it in code, against a real document.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use XPath Tester

  1. Paste XML or HTML, or press Sample.
  2. Type an XPath expression; results update as you type.
  3. Copy matching values.

Features

  • XPath 1.0 via document.evaluate, as in Chrome and Firefox
  • Node results with an absolute path for each match
  • count(), sum(), string() and boolean results
  • XML (case-sensitive) or HTML parsing
  • Clear errors for invalid XML and invalid expressions

Supported formats

You can open

  • XML
  • HTML

You get

  • Copied text

Private by design

Your files are opened and processed by your browser on this device. They are never uploaded to openWorkstand or anyone else, so the XPath Tester is safe for contracts, IDs, photos and work documents. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • XPath 1.0 only, as implemented by browsers; XPath 2.0 and 3.1 functions are not available.

Guide

Testing XPath expressions against XML and HTML

XPath expressions locate parts of an XML or HTML document: they drive Selenium and Playwright locators, Scrapy and lxml scrapers, XSLT stylesheets and many configuration tools. Writing one blind and running a whole test or crawl to see whether it works is slow. This tester evaluates an expression against a document as you type and shows exactly what it matches.

Paths, steps and predicates

An expression is a path of steps separated by slashes. /catalog/book walks from the root to catalog and then its book children; //book finds book elements anywhere. @id selects an attribute and text() the text nodes. Predicates in square brackets filter a step: //book[@lang="fr"] keeps French books and //book[price > 10] compares a child element’s value as a number. .. steps up to the parent, which CSS selectors cannot do.

Functions and result types

XPath 1.0 has functions for strings (contains, starts-with, normalize-space, substring), numbers (count, sum, round) and booleans (not). An expression can therefore return four kinds of result: a set of nodes, a number, a string or a boolean. Node sets appear as a list of matches; the other three appear as a single value you can copy.

XML and HTML modes

In XML mode the document must be well-formed, and the tool reports the parser’s error if it is not. Element names are case-sensitive. In HTML mode the browser’s forgiving HTML parser builds the tree, adding html, head and body if they are missing and turning every element name into lower case, which mirrors what Selenium or Playwright see in a real page.

Namespaces

Many XML formats, such as RSS with extensions, SVG, sitemaps and SOAP, declare a default namespace with xmlns="…". In XPath 1.0 an unprefixed name never matches an element in a namespace, so //url returns nothing in a sitemap even though the elements are right there. Use //*[local-name()="url"], which matches on the name alone.

A worked example

The Sample is a catalogue of three books. //book[price > 10]/title returns one match, the title “XML Developer’s Guide”, because only that book costs more than 10. sum(//price) returns the number 56.85, and //book[@lang="fr"]/author/text() returns the text node “Corets, Eva”. Each node match is listed with an absolute path such as /catalog/book[1]/title, which tells you exactly where in the document it sits.

Debugging an expression that matches nothing

Shorten the expression until it matches something, then add steps back one at a time. Check the case of element names in XML, check for a default namespace, and remember that //book[2] means the second book within each parent; (//book)[2] is the second in the whole document. Whitespace inside elements also counts: normalize-space(.)="Save" is safer than .="Save" for text comparisons.

What this engine is

Expressions are evaluated by the browser’s own XPath engine through document.evaluate, the same one browser automation tools use in Chrome and Firefox. That makes results a faithful preview for those tools, but it also means XPath 1.0 only: functions from XPath 2.0 and 3.1, such as matches() or ends-with(), are not available.

Checked against the current version of the XPath Tester on .

Troubleshooting

The file does not open

Check that it is one of the supported formats above and opens in another app. Damaged files and password-protected PDFs cannot be read until they are repaired or unlocked.

It is slow or stops on a very large file

Everything runs on your device, so speed depends on its memory. Close other tabs, use a computer rather than a phone, or split the file into smaller parts first.

The download did not start

Look for your browser’s download bar or icon. Some browsers ask once before a site may download files; allow it and click the button again.

Frequently asked questions

What is the difference between / and // at the start?

A single slash starts at the document root and follows the exact path, so /catalog/book only matches book elements directly inside the root catalog. A double slash searches the whole document at any depth, which is easier to write but slower on huge documents.

How do I select the second book?

Use a positional predicate: (//book)[2]. Without the parentheses, //book[2] means “every book that is the second book inside its own parent”, which can return several elements or none depending on the structure.

Why does //book return nothing when the XML clearly has book elements?

The document probably declares a default namespace (xmlns="…"). In XPath 1.0 an unprefixed name never matches a namespaced element, so use //*[local-name()="book"] instead.

What is the difference between //title and //title/text()?

//title returns the elements; //title/text() returns their text nodes. Most libraries give you the element’s text either way, but text() skips nested child elements and attributes.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.