XPath tester
Paste HTML or XML, type an XPath expression and see the nodes, strings or numbers it returns, evaluated by your browser's own engine.
XPath
Result
Paste a document and type an expression. The nodes or the value it returns are listed here.
Extracted values
One value per node appears here.
The same expression in code
When to use it
You're scraping with lxml, Scrapy or Playwright and need an XPath expression that finds the right nodes. Paste the HTML or XML, try expressions here and see exactly what each one returns.
What runs the expression
Your browser does, with its built-in XPath 1.0 engine, on a detached copy of what you pasted. An expression can return a set of nodes, a string, a number or true/false. The result panel shows whichever came back.
XPath 2.0 functions such as lower-case() or matches() aren't available here. They aren't in lxml or Scrapy either, which are XPath 1.0 too.
HTML mode and XML mode
- In HTML mode the browser repairs the markup the way it would for a real page. Element names are lowercase and need no namespace prefix, so write
//div, never//DIV. Tables gain atbody. - In XML mode the document must be well formed, and names are case sensitive. A parse error is reported with the line it happened on.
- An XML document with a default namespace, such as a sitemap, has no prefix you can write in XPath 1.0. Match on the local name instead:
//*[local-name()="loc"].
Expressions worth knowing
//a/@hrefreturns the attribute itself, which is usually what you want to extract.contains(@class, "price")matches one class among several. An exact@class="price"fails as soon as the element has a second class.normalize-space()trims and collapses whitespace. So//h2[normalize-space()="Fellrunner 2"]matches even with line breaks in the source.following-sibling::andancestor::walk in directions a CSS selector can't. That's the main reason to reach for XPath.
Questions people ask
How do I test an XPath expression?
Paste your HTML or XML, type the expression and read the results below. Node sets are listed one by one, and expressions that return a string, number or true/false show that value.
How do I select an element by its text?
Use text() or contains(). //a[text()='Next'] matches a link whose text is exactly Next, and //a[contains(., 'Next')] matches any link with Next somewhere inside it.
Why does my XPath return nothing on an XML file?
Often a namespace. If the root element declares a default xmlns, plain element names do not match. Use local-name(), as in //*[local-name()='item'], or register the namespace in your code.
What is the difference between / and //?
A single slash steps to direct children. A double slash searches every descendant at any depth, which is handy but slower on large documents.
Related tools
All tools →Get started
Blocked by bot protection? $5 is 5,000 solves.
No subscriptionCredit never expiresFailed solves are free