lecture 6 of 210 completed

Finding elements

A selector 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 selectors cause a bug that is worse than a failing test. Here it is.

Fern Market is an invented plant shop. A test adds Snake Plant to the basket. Snake Plant is the first card on the page, so the test uses its position:

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 →