lecture 22 of 220 completed

Reading a failing test

NoSuchElement, stale elements and assertion errors. Failures are reports, not riddles.

What you'll learn

  • How to read the common Selenium exceptions
  • What an assertion difference is telling you
  • How to find the cause instead of guessing

When a test fails, most beginners do one of two things. They change something at random and run it again, or they ask a senior engineer. Both are slow.

Selenium names its failures precisely. Each error means one specific thing, and once you know the four names below you can usually find the cause in a minute. Interviewers ask about these too, so it is worth learning them properly.

NoSuchElementException. findElement found no match at that moment. Check in this order:

  1. The selector is wrong. Open the app, inspect the element, compare the real attribute. Most of the time it is this.
  2. The lookup ran too early. The element appears after a delay and you did not wait. The fix is an explicit wait, driver.wait(until.elementLocated(...), 5000), never a sleep.

members only

Keep reading with the full course

The Foundations track and the first 5 lectures of each framework are free. This lecture is part of the paid course, which unlocks every lecture, all three frameworks, and downloads.

See the options →