lecture 7 of 220 completed

Finding elements

A locator based on position breaks the next time someone edits the page. Find elements by what they are instead.

What you'll learn

  • Why a position-based selector can pass while pointing at the wrong thing
  • How to target an element by what it is, not where it sits
  • Which selectors to avoid, and why they break

Position-based locators cause a bug that is worse than a failing test. Here it is.

A test adds the first product to the cart:

full course

Keep reading with the full course

The Foundations track and the first lessons in each framework are free. This lesson needs full course access. A course plan includes all lessons for Playwright, Cypress and Selenium.

See course plans →