Skip to content
gohacks.dev
Testing

XPath Tester

Run an XPath 1.0 expression against XML or HTML and see every matching node, attribute or the number, string or boolean it returns.

Free · No sign-up · Your inputs stay in your browser

Input

Test an XPath expression

Output

0 nodes

Evaluated by the browser's own XPath 1.0 engine, the version libxml2 (PHP's DOMXPath, lxml) and Selenium use. XPath 2.0 functions such as matches() and lower-case() are not part of it. Namespaced documents need a prefix mapping, which this does not set up.

Runs in this browser. Nothing you paste is sent to a server.

Expressions worth knowing

//book[price > 30]/title filters by a child's value, //a[contains(@href, 'github')] matches on part of an attribute, //title[contains(., 'MySQL')]/.. walks up to the parent, and //tr[td[1] = 'Total']/td[2] reads a table cell by its row label. The XPath 1.0 recommendation defines the functions available.

Namespaces

A document with a default namespace, such as XHTML, an RSS feed with extensions or a SOAP envelope, does not match unprefixed names, which is the usual reason an expression that looks right returns nothing. In code, register a prefix (DOMXPath::registerNamespace in PHP) or match with local-name().

Share

Frequently asked questions

Why does my XPath return nothing on a page that clearly has the element?
Either the element is created by JavaScript after load, so it is not in the HTML source, or the document has a default namespace. Check the source, and try //*[local-name()='name'].
Does it support XPath 2.0 or 3.1?
No. Browsers implement XPath 1.0 only, so functions such as matches(), lower-case() and tokenize() are unavailable. Use translate() for case-insensitive matching.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools