Selenium WebDriver 4

Find an element by class name

Easy30 pts~12 min
  • Locators
  • By.className
Practice app · Practice Catalog

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

Test URL
/lab/qa-automation-find-an-element-by-class-name

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

Objective

Use a single class name to locate an “Add to cart” button and add a product.

Your task

  1. 1Open TEST_URL.
  2. 2Find the first element with class “add-to-cart” and click it.
  3. 3Assert #cart-count shows “1”.

Acceptance criteria

  • The button is located with By.className
  • #cart-count shows “1”
  • At least 1 assertion passes

Selenium WebDriver 4 · QA Automation · Locators & the DOM