We use cookies.This website uses essential cookies to operate core features. With your consent, we also use analytics cookies to understand traffic and improve the service. For more details, see our .
If this tool helped you, you can buy us a coffee ☕
Test XPath expressions right in your browser and see matches instantly — great for web scraping, data collection, and front-end debugging.
One prefix mapping per line, in the format prefix=URI. Default namespaces must be referenced using a custom prefix in XPath.
Please enter content and an XPath expression to see results.

PYC Decompiler
Restore Python bytecode .pyc files into readable source code for easy code auditing and learning. Supports mainstream versions.

JSON to TypeScript Converter
Automatically convert JSON data into TypeScript interfaces or type aliases for frontend data modeling and API integration.

Code Compare
Professionally compare differences between two texts or code snippets. Highlights additions, deletions, and modifications to assist with code review, document merging, and version control.
Whether you're writing a web scraper to extract product price links, debugging element locators in automated test scripts, or just curious about how many specific tags exist in an HTML snippet—XPath lets you locate them with a single line. But did you write the XPath correctly? Expressions are easy to mistype. Our Online XPath Tester allows you to paste an HTML/XML document, write your XPath, and instantly see the match count and highlighted content, saving you the hassle of repeatedly refreshing pages or opening developer tools.
XPath is a path language used to find nodes in an XML document, similar to directory paths in a file system. For example, //div[@class='price'] means "all div elements with a class attribute equal to price". Think of it as giving elements in a document an "address" that you can use to retrieve them directly. Developers frequently use it to extract data from web pages or control automated workflows.
//a/@href extracts the addresses of all hyperlinks.Suppose you have a simple product HTML snippet (paste this into the document box):
<div id="products">
<div class="item">
<span class="name">Wireless Mouse</span>
<span class="price">$39.9</span>
</div>
<div class="item">
<span class="name">Mechanical Keyboard</span>
<span class="price">$129</span>
</div>
</div>You want to extract all product names. Enter //span[@class='name']/text() in the XPath box. Click test, and the results area will show "Matched 2 nodes" and list:
1. Wireless Mouse
2. Mechanical Keyboard
If you want to get both the name and price at once, you can use a union selection or return the parent node of the elements, but beginners should stick to simple expressions first.
Let's look at a comparison: If you write //span[@class='price'] (without /text()), the match result will show "2 nodes", but each node is the entire tag like <span class="price">$39.9</span>—because XPath returns nodes by default, not text. If your goal is to get the numbers, remember to add /text() or string().
//tag often won't match, requiring you to register a namespace prefix first. Our tool currently only supports matching without namespaces or with explicit prefixes. When encountering namespaces, please manually remove them first or use the local-name() function instead.<Div> and <div> are two different nodes. Pay attention to this when writing expressions.// Causing Performance Issues: Although the tool processes small documents quickly, abusing // in real, large documents will scan all nodes. It's recommended to use specific paths like /html/body/div[1]/ to improve efficiency.//div [@class=...] (with a space before the bracket) is a syntax error, and the tool will prompt "Invalid expression". Avoid adding unnecessary spaces when writing expressions.text() Gets All Text: text() only returns direct text child nodes; text inside nested elements won't be automatically merged. To get all text, you can use string() or normalize-space().local-name() in your expression or remove the namespace declaration first.@class='value' in XPath but the actual attribute value has leading/trailing spaces. You can use //* to see all elements first, then gradually narrow it down.contains() function supported?//div[contains(@class, 'price')] can match div elements where the class attribute contains "price".//a to return all 'a' elements, and the result box will show the node's text (inner text). To get the href attribute, use //a/@href, but note that it returns an attribute node, so the text will be empty. You can write two expressions and test them separately, or use a multi-expression feature (if the tool provides one).[object Text], not the text I want/text() or /string() to the end of your expression to get the string.Now you can try your own HTML and XPath expressions in the input boxes above.