Skip to content

XPath Tester

Evaluates an XPath or CSS selector against XML or HTML and lists every matched node.

Runs an XPath 1.0 expression or a CSS selector against an XML or HTML document and shows every node it matched, with the absolute path to each. Evaluation is the browser’s own, so what you see here is what `document.evaluate` will do in your code.

🔒 Runs entirely in your browserxpathxmlselectortest

XPath 1.0 expression

Query language

Document

Read as

Drop a file

Read in this tab only.

Results

Results appear here as you type.

How it runs

  • · Evaluation is the browser’s document.evaluate (XPath 1.0) and querySelectorAll. The result typing — node set, number, string, boolean — the absolute path for each node, and the namespace-prefix handling are this tool’s.
  • · XML mode reads strictly and reports what is wrong; HTML mode reads leniently, the way a browser does. HTML normalises tag names to lowercase, so //DIV is wrong and //div is right.
  • · In a document with a default namespace (xmlns="…"), an unprefixed name matches nothing — that is XPath 1.0’s rule. Use the _ prefix, as in //_:item.
  • · XPath 2.0 and 3.x functions (matches, ends-with, lower-case) are not in any browser. contains·starts-with·translate·normalize-space are what 1.0 gives you.
  • · The document is read in this tab only and is not uploaded anywhere.

For JSON, the JSONPath tester or the jq playground is the right tool.

How to use it

  1. Choose how the document is read

    XML mode is strict and reports what is malformed. HTML mode is lenient the way a browser is, and normalises tag names to lowercase.

  2. Write the expression

    XPath or a CSS selector — the toggle switches which. The example buttons cover attributes, predicates, namespaces, comment nodes and the scalar-returning functions.

  3. Read the result type first

    XPath returns four kinds of thing, and only one of them is a node set. `count()`, `string()` and `boolean()` give you a single value, shown on its own rather than as an empty match list.

Common questions

My expression matches nothing and the document looks fine.

Almost certainly a default namespace. If the document has `xmlns="…"` on its root, XPath 1.0 says an unprefixed name matches nothing at all — you have to bind a prefix. Here that prefix is `_`, so `//item` becomes `//_:item`.

Why does `matches()` not exist?

Because browsers implement XPath 1.0 only. `matches`, `ends-with`, `lower-case` and the rest arrived in 2.0 and no browser has it. The 1.0 toolkit is `contains`, `starts-with`, `translate` and `normalize-space`.

XPath or CSS — which should I use?

CSS is shorter and enough for most scraping. XPath can walk upward (`..`, `ancestor::`), match on text content, and return numbers and strings, none of which a selector can do. This page runs both so you can compare them on the same document.

Does it fetch a page for me?

No. You paste or drop the document and it is read in this tab. Fetching would need a proxy — the browser will not let a page read another origin — and that proxy would see everything you tested.

Feed it from

Next

These accept what this tool produces, so the result can go straight in.