XPath and CSS selector tester
The short answer: paste HTML, type an XPath or a CSS selector, and see every element it matches, with a count. It runs in your browser with the browser's own engines (document.evaluate for XPath, querySelectorAll for CSS), so what matches here matches in a real page.
0 matches
Nothing you paste is sent anywhere.
XPath and CSS, side by side
| Find | XPath | CSS |
|---|---|---|
| every link | //a | a |
| by id | //*[@id='main'] | #main |
| by attribute | //input[@type='email'] | input[type="email"] |
| class contains a word | //li[contains(@class,'sale')] | li[class*="sale"] |
| direct child | //ul/li | ul > li |
| any descendant | //ul//a | ul a |
| second of its kind | //li[2] | li:nth-of-type(2) |
| by its text | //a[text()='Home'] | no CSS form |
To turn one into the other, use the XPath to CSS converter in the locator generator.
Selectors in tests that last
A selector tied to the page's structure breaks when the structure changes. Playwright's own advice is to prefer locators by role, label and text over CSS and XPath, and the Playwright locator generator writes those for you from the same HTML.
FAQ
How do I test an XPath online?
Paste the page's HTML (or the part you care about), choose XPath, and type the expression. Every matching element appears below with a count. The tester uses your browser's own XPath engine, so the result is what the browser itself would find.
How do I test a CSS selector?
Choose CSS selector and type it. The tester runs it with querySelectorAll, the same call Playwright and every browser use for CSS.
Why does my XPath work here but not in my test?
Your test runs against the live page, which may have changed or not finished loading, and some content is inside iframes or shadow DOM that a plain XPath does not reach. Playwright's getByRole and getByText locators handle loading and shadow DOM for you.