XPath and CSS locator generator for Selenium and Playwright
Paste a page's HTML, click any element, and get locators ranked from most to least stable, each checked for uniqueness, with code ready to paste into your Selenium or Playwright test.
Page
Paste HTML from DevTools (right-click → Inspect → Copy outerHTML of the form or section). Scripts and event handlers are removed before preview.
Locators
Test a selector
Type any CSS selector or XPath (starting with / or ( ). Matches light up in the preview.
Export every field on this page as a ready Page Object class.
- Best unique locator for every input, button, select and link
- Playwright TypeScript or Python, Selenium Java or Python
- Field names generated from labels, ready to commit
Choosing locators that don't break
Which locator should I use first?
In Playwright, prefer user-facing locators: getByRole with a name, then getByLabel, getByPlaceholder or getByText, and getByTestId when the team adds test IDs. In Selenium, prefer a stable id, then name, then a short CSS selector on a stable attribute. Use long XPath only as a last resort.
Why is this id flagged as auto-generated?
IDs like pwd-8f3a2c91, ember123 or :r4: are created by frameworks and change between builds or page loads. A test pinned to them breaks without any real change to the page.
CSS or XPath?
CSS is shorter, faster to read and works the same in Selenium and Playwright. XPath is needed when you must match by visible text in Selenium, or walk from a label to its input. Both are fine when they are short and use stable attributes.
My locator matches more than one element. What now?
Scope it to a unique parent (a form, a card, a table row), add another attribute, or in Playwright chain locators: page.locator('.card').filter({ hasText: 'iPhone 16' }).getByRole('button').
Is the accessible name here exactly what Playwright uses?
It follows the main rules (aria-label, aria-labelledby, label, text, alt, title, placeholder) but is a simplified version. Confirm tricky cases with Playwright's codegen or the locator picker in its Inspector.