🌳XPath Tester Online - CSS Selector Tester & Generator
Scrapers, end-to-end tests and XML config work all mean tweaking an XPath or CSS selector until it hits exactly the right nodes. Paste XML or HTML (the type is detected automatically, or switch it yourself) and type an expression to see results live: matched elements, attributes and text nodes are highlighted in a pretty-printed source view, and a list shows each match’s absolute path, attributes and text. XPath runs on the browser’s built-in XPath 1.0 engine, so besides node sets you get the number, string or boolean result of functions such as count(), sum(), string() and boolean(). Documents with a default namespace — Atom, SVG, SOAP, Maven pom.xml — need prefixes in XPath 1.0, so the tool collects every namespace declaration and assigns an ns prefix to the default one; you can add or edit mappings too. It also works the other way round: click any element, attribute or text in the source view and you get several verified XPath and CSS selectors that match only that node, preferring stable hooks such as ids, attributes and text, shortest first, ready to copy or drop back into the query box. Includes an XPath and CSS cheat sheet and three sample documents. Everything is parsed locally in your browser; nothing is uploaded.
Free · No sign-up · Runs in your browserLast updated:
How to use XPath & CSS Selector Tester
- 1Paste XML or HTML, or load an example
- 2Pick XPath or CSS, type an expression and check the highlights and match list; use prefixes for default namespaces
- 3Click a node in the source view and copy the generated unique XPath / CSS selector
FAQ
- Why doesn’t //entry match anything in my Atom or SVG file?
- Those documents declare a default namespace with xmlns="…", and in XPath 1.0 an unprefixed name only matches elements with no namespace. Use the prefix the tool assigns, e.g. //ns:entry/ns:title, or ignore namespaces with //*[local-name()='entry']. CSS selectors don’t have this restriction.
- How reliable are the generated selectors?
- Every candidate is actually run against the current document and only shown if it matches the clicked node and nothing else. The tool prefers ids, name, class, data-* attributes or short text, then anchors on the nearest uniquely identifiable ancestor, and only falls back to an indexed absolute path. Selectors can still break when the page structure changes — indexed paths are the most fragile.
- Is XPath 2.0 or 3.0 supported?
- No. Browsers only ship XPath 1.0, so 2.0+ functions such as matches(), lower-case() and sequence expressions aren’t available. The common ones — contains(), starts-with(), normalize-space(), translate(), count(), sum(), position(), last() — and all axes (ancestor, following-sibling and so on) work.
- Why do HTML paths start with /html/body?
- When browsers parse HTML they add missing <html>, <head> and <body> elements and lowercase tag names. That matches the DOM seen by Chrome DevTools, Selenium and Playwright, so the generated selectors work there directly. Switch the document type to XML if you need the markup parsed exactly as written (it must be well-formed).