Playwright

Handle lists with nth and first

Medium70 pts
  • List index
  • first()
  • last()
  • nth()
Practice app · Practice Catalog

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

Test URL
/lab/playwright-handle-lists-with-nth-and-first

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

Objective

Interact with specific items in a list using index-based positional locators.

Your Task

  1. 1Navigate to the practice catalog page at TEST_URL.
  2. 2Click the 'Add to cart' button (.add-to-cart) in the first product card.
  3. 3Click the 'Add to cart' button (.add-to-cart) in the last product card (or by index).
  4. 4Assert that the cart counter (#cart-count) displays '2'.

Validation Checks

  • Practice catalog application is loaded at TEST_URL
  • First product card's 'Add to cart' button is clicked
  • Last product card's 'Add to cart' button is clicked
  • Cart counter (#cart-count) displays '2'
  • At least 1 assertion passes

Playwright · Playwright Practice Track · Locators & auto-waiting