#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Free tool by Uncodemy · Noida

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

Your locators are ready to generatePick an element, then get ranked locators with copy-ready code.Free. Enter your name and WhatsApp number once.

Test a selector

Type any CSS selector or XPath (starting with / or ( ). Matches light up in the preview.

Page Object Model

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.