How to use the Selenium Locator Generator from HTML
- 1. Copy the elementIn DevTools right-click the element › Copy › Copy outerHTML.
- 2. Paste and choose a languagePaste one or more elements and pick Java, Python, C# or JS.
- 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-38271change 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.