XPath Selector

Test XPath expressions on XML, HTML, XHTML or SVG in your browser. See every matching node, attribute or text, or the value of count() and string(). Uses the browser's built-in XPath 1.0 engine, shows the match count, and resolves namespace prefixes from the document.

About this tool

What is XPath?

XPath (XML Path Language) is a query language for selecting parts of an XML or HTML document: elements, attributes, text, or computed values such as counts. It is used in XSLT, Selenium and Playwright locators, web scraping and many XML APIs. This tool runs your expression with the browser's own XPath engine and shows exactly what it selects.

How to use

  1. Choose the Document type: text/html, text/xml, application/xml, application/xhtml+xml or image/svg+xml.
  2. Paste the markup into the Input document editor (an example is filled in to start with).
  3. Type an expression in the XPath box, for example //city/name, and press Enter or click Select.
  4. Matches appear in the Output document editor, one per line, with a message such as "2 nodes matched." Copy or download them with the buttons in the editor corner.

Features

  • XML and HTML: HTML is parsed leniently like a web page; XML types report syntax errors
  • Any result type: node sets are listed in document order; numbers, strings and booleans (from count(), string(), comparisons) are shown as a single value
  • Attributes and text: attribute matches are shown as name="value", text nodes as plain text
  • Namespaces: prefixes declared on the root element can be used in the expression
  • Default namespace hint: if nothing matches because the document has a default namespace, the tool tells you and suggests local-name()

XPath examples

For the sample document of <city> elements with <name> and <population> children:

ExpressionSelects
//cityEvery city element
//city/name/text()The text of each city name
//city[1]/nameThe name of the first city
//city[population > 5000000]/nameNames of cities with more than 5 million people
count(//city)The number of cities (a number result)
//*[local-name()='name']Every name element, ignoring namespaces
//a/@hrefEvery href attribute of links (HTML)

FAQ

Why does my expression match nothing on a document with xmlns="..."?

When the root element declares a default namespace, unprefixed names in XPath 1.0 only match elements with no namespace. Use //*[local-name()='item'], or choose text/html if the document is really HTML.

Which XPath version is supported?

XPath 1.0, which is what browsers implement. XPath 2.0/3.1 functions such as matches() or string-join() are not available.

Is the document sent anywhere?

No. Parsing and evaluation are done by your browser and nothing is uploaded.