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:
- The selector is wrong. Open the app, inspect the element, compare the real attribute. Most of the time it is this.
- 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 asleep.