Test XPath expressions to query and extract XML data.
XPath (XML Path Language) is the standard query language for selecting nodes in XML documents—and it works equally well for querying HTML. It is used in web scraping, XML data processing, XSLT transformations, Selenium test automation, and document processing pipelines. Our XPath Tester lets you paste any XML or HTML document and test XPath expressions against it instantly, displaying all matching nodes as formatted output. Get immediate feedback on your expressions without writing or running any code.
Testing an XPath Expression
| Expression | Description |
|---|---|
/ | Root node or child separator |
// | Descendant at any level |
@ | Attribute selector |
[n] | Index predicate (1-based) |
[@attr] | Has attribute |
[@attr='value'] | Attribute equals value |
text() | Text content of node |
contains(@class, 'x') | Attribute contains substring |
Selenium and Playwright Test Automation
XPath locators are widely used in Selenium WebDriver and Playwright tests to find elements in the page DOM when CSS selectors are insufficient. Test your XPath expression against the page's HTML before adding it to your test suite to confirm it selects the correct element(s). Use the attribute-based predicates (//button[@type='submit']) to write robust locators that do not depend on element position.
Processing XML Data Files
Configuration files, SOAP API responses, RSS feeds, and data exports often use XML. XPath lets you query these files programmatically—extracting specific fields, filtering by attribute values, or counting elements. Test your XPath expressions here against a sample XML document before using them in your XSLT, Python (lxml), Java (javax.xml), or C# (XDocument) code.
Web Scraping Locators
Web scraping tools like Scrapy, BeautifulSoup with lxml, and browser automation frameworks use XPath to locate elements in scraped HTML. Test locators against the HTML source of the target page to verify they match exactly the elements you need—and that they will remain stable when the page content changes but the structure does not.
Q: Does this tool work with HTML as well as XML?
A: Yes. The tool parses HTML input using the browser's built-in DOMParser and evaluates XPath against it. This makes it useful for testing Selenium/Playwright locators and web scraping expressions directly against page HTML.
Q: What is the difference between XPath and CSS selectors?
A: Both select elements in an HTML/XML document. CSS selectors are simpler and widely supported in browsers and scraping tools, but XPath is more powerful—it can select by text content, navigate up to parent elements, and work with any XML document, not just HTML. Use XPath when CSS selectors cannot express the selection you need.
Q: Is my XML/HTML data safe to paste here?
A: Yes. All XPath evaluation happens entirely in your browser. Your document is never uploaded to any server, stored, or transmitted. This makes the tool safe to use with proprietary data, internal HTML, and sensitive XML documents.
Q: Do I need an account to use this?
A: No. The tool is completely free with no registration required.