XPath Tester

Test XPath expressions against XML and HTML with live match results

Use this free XPath tester to test XPath online against XML or HTML. Enter an expression, see matching nodes, paths, and scalar values instantly. Built for debugging scrapers, UI tests, and XML queries. 100% client-side. Your data never leaves your browser.

From the blog
Emergent Leader Pattern in Distributed Systems

How peer-to-peer clusters pick a coordinator by age, without ever running a leader election

Read

Developer tools Latest posts Explainers

Results 0

Enter an XPath expression and document to see results

XPath Quick Reference

Axes & Paths

/Child from root or context
//Descendant at any depth
.Current node
..Parent node
@attrAttribute
*Any element

Predicates & Functions

[1]First node
[last()]Last node
[@id='x']Attribute equals
contains()Substring match
text()Text nodes
count()Node count

XPath Examples

Click a row to load the expression against the sample document.

Expression What it selects
//book/title All book titles
//book[@category='web']/title Titles of web-category books
//book[price>30] Books priced over 30
//book/author All author elements
count(//book) Number of books
string(//bookstore/book[1]/title) First book title as string
//div[@id='main']//a Links inside #main
//*[contains(@class,'card')] Elements with class containing card
//h2/text() Text nodes of h2 elements
boolean(//form) True if a form exists

XPath Guide

What is XPath?

XPath (XML Path Language) is a query language for selecting nodes from an XML or HTML document tree. It is used in Selenium, scrapers, XML processors, XSLT, and browser DevTools. This XPath tester evaluates XPath 1.0 expressions with your browser’s native engine.

HTML vs XML mode

HTML mode parses markup with the HTML parser, which is forgiving and suitable for web pages. XML mode requires well-formed XML and surfaces parse errors when tags are mismatched. Pick the mode that matches your source document.

Writing effective XPath

  • Prefer specific paths: //div[@id='main']//li is clearer than a long chain of positional indexes.
  • Use predicates: Filter with [@attr='value'], [contains(.,'text')], or [position()<3].
  • Mind namespaces: Prefixed XML may need local-name() tricks in XPath 1.0 when prefixes are unknown.
  • Scalars matter: Wrap selections in string(), count(), or boolean() when you need a single value.

Using this XPath tester

Paste a document, enter an expression, and review the Results panel. Node matches show type, a simple path, and a snippet. Scalar results show the typed value. Use Sample to load a bookstore XML or HTML page, and Share Link to copy a URL with your expression and mode. For related text tooling, try the Regex Tester or validate structured data with the JSON Validator.

XPath Tester FAQ

What is an XPath tester?

An XPath tester lets you write an XPath expression and evaluate it against an XML or HTML document. You see matching nodes or scalar values instantly, which helps debug scrapers, tests, and XML queries.

How do I test XPath online?

Paste your XML or HTML into the document field, enter an XPath expression, and review the matches. This tool runs in your browser using native XPath 1.0 evaluation.

Does this tool support XPath 2.0 or 3.0?

No. Browsers implement XPath 1.0 via document.evaluate. Expressions that require XPath 2.0+ features will not work here.

Should I use HTML or XML mode?

Use HTML for web pages and fragments. Use XML for well-formed XML such as feeds or config files. XML mode reports parse errors when the markup is invalid.

Is my data safe when using this XPath tester?

Yes. Evaluation runs entirely in your browser. Your document and XPath expression are never uploaded to a server.

How do I select elements by attribute in XPath?

Use a predicate with @. Examples: //div[@id='main'], //a[@href], and //input[@type='text'].

What is the difference between / and // in XPath?

/ selects along the child axis from the root or context. // selects descendants at any depth. /html/body/div is a direct path; //div finds every div.

Can XPath return text, numbers, or booleans?

Yes. Node expressions return node-sets. Functions like string(//title), count(//item), and boolean(//error) return scalar values. Need pattern matching on text instead? Try the Regex Tester.