You triage: which test cases are solid, which are fragile, which will haunt you next release.
Locators deserve the same triage. This lesson is pure practice: build a locator inventory for a real page, the exact prep step of any automation task.
Before automating a flow, professionals do a locator pass: walk the flow manually with DevTools open and record a locator for every element they'll touch. It surfaces problems early (duplicated ids, missing test attributes) and turns the coding step into assembly. Today you'll build the locator inventory for saucedemo's login → add to cart → checkout flow — the same inventory your Selenium tests in the next suite will use.
Grab the ready-made locator inventory template from the downloads page, or start from this shape:
| Page | Element | Locator | Type | Matches | |-----------|--------------------|-------------------------------|------|---------| | Login | username field | #user-name | CSS | 1 | | Login | password field | #password | CSS | 1 | | Login | login button | #login-button | CSS | 1 | | Login | error message | [data-test='error'] | CSS | 1 | | Products | page title | .title | CSS | 1 |
The console one-liner that makes this fast — it prints the match count for a CSS selector:
$$("#login-button").length
$$(".title").length
$x("//button[text()='Add to cart']").length> $$("#login-button").length
1 // unique — inventory-worthy
> $$(".title").length
1
> $x("//button[text()='Add to cart']").length
6 // not unique — fine for "all buttons", wrong for "the button"Below is a small fake shop page. Type CSS selectors or XPath into the box and watch matching elements light up green — exactly what $$() and $x() do in DevTools, without leaving the lesson. Then work through the eight challenges; your progress saves in this browser.
a shared class, or [data-test^="add"]
chain two classes with no space between them
//h3[text()='...']
//h3[text()='Pocket Debugger']/ancestor::div[contains(@class,'product')]//div[@class='product-price']
The username field can be reached as #user-name, [data-test="username"], [name="user-name"], .form_input:nth-child(1)… all match. Apply the priority you learned: id first (unique and short), data-test equally good, positional last. Write the winner in the inventory, not all four.
By.cssSelector("#login-button") is just your inventory row wearing Java syntax. Testers who skip the locator pass end up debugging locators and Selenium simultaneously — two new skills at once, in the dark. You'll be debugging only one.Finish the inventory for the full flow. Walk it manually (standard_user / secret_sauce) with DevTools open and record verified locators for:
Every row needs a verified match count of 1. Keep the file — Suite 04 automates this exact flow with this exact inventory.
#add-to-cart-sauce-labs-backpack
.shopping_cart_badge
.shopping_cart_link
.inventory_item_name (cart page)
#checkout
#first-name #last-name #postal-code #continue
.summary_subtotal_label
#finish
.complete-header