Selenium WebDriver 4

Handle duplicate matches deterministically

Hard120 pts~45 min
  • Duplicate elements
  • Deterministic locators
Practice app · Practice Catalog

A product catalog with ids, names, classes, links, data-testids and duplicate buttons for locator practice.

Test URL
/lab/selenium-handle-duplicate-matches-deterministically

Your starter code already declares TEST_URL — never hardcode a host.

Objective

Every card has an identical “Add to cart” button — pick the Cypress Hoodie’s without relying on indexes.

Your task

  1. 1Open TEST_URL.
  2. 2Scope to the card containing “Cypress Hoodie” (by data-testid or by its .product-name text).
  3. 3Click that card’s .add-to-cart, then its “View details” link.
  4. 4Assert #cart-count shows “1” and the URL ends with “#/products/tqa-300”.

Acceptance criteria

  • No positional index is used
  • #cart-count shows “1”
  • The final URL contains “#/products/tqa-300”
  • At least 2 assertions pass

Constraints

  • Do not pick elements by index (list[2], :nth-child, (//button)[3]).

Selenium WebDriver 4 · Selenium · Locators & the DOM