A CSS selector, such as “#email” or “[data-testid="save"]”, picks elements by tag, id, class, attributes and position. XPath is a path language that can also walk up to parents and match by text, as in “//button[contains(., 'Sign in')]”. Test-automation tools use both to find the element to click or check.
How the tool evaluates
The HTML is parsed by your browser's own HTML parser into an inert document: it is never shown as a page, its scripts never run, and nothing it links to is loaded. Queries run on that parsed tree, not on the source text, and the two can differ. The parser adds a tbody to tables and corrects broken markup, so “table > tbody > tr” matches a table whose source has no tbody. That tree is what your test really sees.
A match is marked in the source view only when one of its attributes appears there exactly once; otherwise it is only listed.
CSS or XPath?
CSS selectors are shorter, usually faster, and supported by every test framework. XPath can do what CSS can't: go up from a match, as in “//button/ancestor::form”, or find an element by its text. Browsers implement XPath 1.0, which has no regular expressions.
Stable selectors
Prefer an id or a test attribute such as data-testid over long paths and positions: “#email” survives a redesign that breaks a positional path. The suggestions under the matches follow that order and flag the fragile ones, but a suggestion is only as stable as the page. RoboQA, which makes these tools, lets you describe a test in plain English instead of writing selectors.
XML and namespaces
With “Treat input as XML”, the input is parsed as XML and parse errors are reported. XPath 1.0 has no default namespace, so in a document whose elements are in a namespace, “//item” finds nothing: map a prefix to the namespace URI in the prefix map and write “//p:item”.
Limits and privacy
The HTML can be up to 1,000,000 characters and the query up to 5,000; the list shows the first 500 matches with the real total. Above 200,000 characters, queries run only when you press Run. A pathological query on a huge document can freeze the page, and it can't be stopped once started. Your HTML never leaves your browser. Like the rest of the site, the page records a visit when it loads, but not what you paste.
How to use
- Paste HTML, load a file or load the sample, then choose CSS selector or XPath.
- Type a query; the matches appear as you type, with their paths, attributes and text.
- Use a suggested selector, or copy the matches or the query.
Features
- Node sets, strings, numbers and booleans from XPath, including attribute and text nodes.
- Suggested selectors for the first match, each run to show how many elements it matches.
Common uses
- Writing UI tests. Check that a locator finds exactly one element before you use it.
- Debugging flaky locators. Paste the page's HTML from the failing run and see what the selector matches.
- Checking data in pages. Read values with XPath functions such as count() and string().
Frequently asked questions
How do I test an XPath online?
Paste the HTML, choose XPath and type the expression. Nodes are listed with their paths, and expressions such as count() or string() show their value and type.
How do I test a CSS selector?
Paste the HTML, choose CSS selector and type it; the count and matches appear as you type.
What is the difference between XPath and CSS selectors?
Both find elements. CSS is shorter and supported everywhere; XPath can also go up to parents and select by text.
Why doesn't my selector match the element I see in the source?
Queries run on the parsed tree, which can differ from the source: the parser adds tbody, moves misplaced elements and fixes broken tags. Content that scripts add later isn't there at all, because scripts never run here.
What is XPath 1.0 and what does it lack?
The XPath version browsers implement. It has no regular expressions, no lower-case() or ends-with() and no default namespace; those arrived with XPath 2.0.
Why is my XPath with a namespace empty?
In XPath 1.0 an element in a namespace needs a prefix in the query. Tick “Treat input as XML”, map a prefix to the namespace URI and use it, as in “//p:item”.
Is my HTML uploaded?
No. It is parsed and queried in your browser and never sent anywhere or saved. The page itself records a visit when it loads, as every page here does.
Is it safe to paste a page with scripts?
This tool never runs them: the HTML goes into an inert document, nothing it links to is loaded, and results are shown as text. Still treat pages from unknown sources with care.
Need to test a whole website, not just a snippet?
RoboQA tests real pages and user journeys in a browser: logins, forms, clicks and full flows. See what RoboQA can test or compare plans.