XPath and CSS selector tester
Paste the HTML of the page (or a fragment of it), type a selector, and see exactly which elements it matches. The HTML is parsed into a detached document in your browser: no script in it runs, no image or stylesheet loads, and nothing you paste is sent anywhere.
CSS selector or XPath: which should a test use?
Both find the same elements; they differ in what they can express and in what breaks them. A CSS selector cannot select by text or walk up to a parent; XPath can (//li[.//span[normalize-space()="Item 7777"]]/button, or .. to climb). In a browser, CSS is the faster of the two: measured on 2026-11-04 on a page of 10,000 list items, 200 runs each, the median in-page lookup for an id was under 0.1 ms by CSS and 3 to 9.5 ms by XPath in Chromium 151, Firefox 153 and WebKit 26.5, and for a data-testid attribute under 0.1 ms against 3 to 7 ms. The exception was positional selectors: WebKit took 111 ms for li:nth-child(7777) against 2 ms for li[7777]. In a test, neither cost matters next to a page load. What matters is which selectors survive a change: when one row was inserted at the top of that list, the id, data-testid, class and text selectors still found the same button in all three engines, and both positional forms, CSS and XPath, pointed at the row above it.
The practical rule: prefer an id or a test attribute, then a role or a label, then a class; use text through your test library's own locators (Playwright's getByRole and getByText) rather than through XPath; and avoid positions. The full measurement, with the code that produced it, is in XPath vs CSS selectors for test automation.
Mistakes this tool shows you quickly
//li[@class="row"]matches only an element whose whole class attribute is exactlyrow. For an element with several classes usecontains(concat(" ", normalize-space(@class), " "), " row "), or a CSS class selector, which matches one class among many.text()="Pay"fails when the text has surrounding whitespace or sits in a child element.normalize-space()="Pay"trims;.//*[normalize-space()="Pay"]looks inside.li:nth-child(3)counts every sibling element;li:nth-of-type(3)counts onlylisiblings. XPath'sli[3]is the second kind.- An XPath that selects an attribute (
//a/@href) is shown by the element that owns it, because a test can only act on an element. - The pasted HTML is parsed as a browser would parse it: an unclosed tag is repaired, and the document gets an
html,headandbodyeven when you pasted a fragment.
How the recorder stores locators
Every step a recorded test captures keeps several locators for its element in xpath_details.json, one of the seven files a session produces, so that when the first one stops matching, a fallback can rescue the step and the run shows which one did. This page uses the same two languages to let you check a locator by hand.