#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 · JAVA · PYTHON · C#

Selenium Locator Generator: Paste HTML, Get the Best Locator

Turn copied outerHTML into stable, ranked locators and ready-to-paste code.

  • 🏆 Ranked by stability
  • 🧪 Uniqueness checked
  • 💻 4 code styles

How to use the Selenium Locator Generator from HTML

  1. 1. Copy the elementIn DevTools right-click the element › Copy › Copy outerHTML.
  2. 2. Paste and choose a languagePaste one or more elements and pick Java, Python, C# or JS.
  3. 3. Copy the locatorUse the recommended locator, or another from the full list.

How locators are ranked

The generator parses your snippet and builds every sensible strategy for each element, then recommends the most stable unique one. The order is: a unique id, a dedicated test attribute (data-testid, data-test, data-qa), name, link text for links, a short CSS selector of tag and classes, then XPath by placeholder or visible text.

Example: for <input type="email" id="email" name="userEmail" class="form-control"> the recommended Java locator is driver.findElement(By.id("email")). For the button with data-testid="login-submit" it suggests a CSS attribute selector, which survives styling changes. Every other strategy it found is listed below the recommendation, with a note when a locator matches more than one element.

Things to watch

  • Dynamic ids such as input-38271 change on every load. If you see numbers, prefer a test attribute or a starts-with XPath.
  • Classes for styling like btn-primary may be shared by many elements. The tool counts matches inside your snippet and marks non-unique ones.
  • Text locators break when copy changes or the site is translated.
  • Paste more context (the parent form) to make uniqueness checks meaningful.

Uniqueness is checked only within what you paste, so confirm on the real page; the XPath tester helps. The HTML is parsed in your browser and never uploaded. Keep the Selenium locators cheat sheet handy for patterns the generator does not cover.

Frequently asked questions

Does it work for Playwright?

Yes. Choose JavaScript to get page.locator() code; link text uses getByRole('link').

Can it handle a whole page?

It analyses up to 15 elements per paste. Paste the part of the page you are automating.

Is the Selenium Locator Generator from HTML free?

Yes, the Selenium Locator Generator from HTML is free. The first time you generate your first locators, you are asked for your name and WhatsApp number once. After that, this and every other Uncodemy tool opens straight away without the form.

More free tools

See all free tools