Skip to content
app.shubraj.com

Locator Builder

Paste your HTML, click an element, and get reliable locators for it. Each one is checked against the page, so you can see which are unique and which are fragile.

1. Paste your HTML

Scripts don’t run. The page is only used to read its structure.

2. Click an element

Or pick from the element tree (0)
  • Nothing to show yet.

3. Locators

Click an element in the preview above to get locators for it.

Test your own selector

Stable Locators for Selenium, Playwright and Cypress

Flaky tests usually start with brittle locators. This tool reads the HTML you paste, lets you click any element, and builds a ranked list of ways to find it: test IDs, roles and labels, attributes, CSS paths and XPath. Every locator is run against your page so you know whether it matches exactly one element.

What you can do

  • Click an element in a live preview, or choose it from the element tree.
  • Locators ranked unique first and then by stability: test IDs, ids, roles, labels, names, text, classes and positions.
  • Generated code for Playwright (JS and Python), Selenium (Python and Java) and Cypress.
  • Warnings for auto-generated ids and positional selectors that break when the layout changes.
  • A box to test your own CSS or XPath and highlight what it matches.

Good to know

  • Prefer test ids, roles and labels. Text, classes and positions change more often.
  • Auto-generated ids (like btn-48291 or css-1x2y3z) are marked fragile, and utility classes such as Tailwind’s are skipped when building CSS.
  • Dynamic content added by JavaScript isn’t in pasted HTML. Copy the rendered HTML from your browser’s DevTools (Elements → Copy outerHTML) for the most accurate results.
  • Shadow DOM and iframes inside the pasted HTML aren’t analysed. Your HTML never leaves your browser.

Frequently asked questions

How do I get a unique XPath or CSS selector for an element?

Paste your HTML, click the element in the preview, and pick a locator marked “1 match · unique”. Stable options like test ids, ids and roles are listed first.

What is the most reliable locator for test automation?

A dedicated test id such as data-testid, then accessible roles and labels, then ids and names. Text, CSS classes and positional selectors are the first to break.

Why is an id marked fragile?

Ids that contain long numbers, hashes or framework prefixes are often regenerated on every build, which makes tests fail.

Can it produce Playwright and Selenium code?

Yes. Choose Playwright (JavaScript or Python), Selenium (Python or Java) or Cypress and copy the ready-to-use line.

Is my HTML uploaded?

No. Everything runs in your browser, and scripts in your HTML are not executed.