We use cookies to analyze site traffic and show personalized ads. You can accept all cookies or decline personalized advertising.
Learn more in our Privacy Policy.
Understand the mental model: DOM → HTML Element → Locator → WebElement.
findElement and findElements.Before you can click, type, or read anything in Selenium, you must find the correct element.
If you don't fully understand how Selenium sees the page:
A solid mental model of how Selenium goes from locator → WebElement will make all later topics (locators, waits, page objects, etc.) much easier.
Before starting this lab, you should:
<button>, <input>, <a>, <div>, etc.).By.id("login-button") (even if you're not comfortable with all types yet).findElement(locator) → returns one WebElement (or fails if none found).findElements(locator) → returns a list of WebElements (can be empty).value, href, etc.)By.* everywhere.A locator is just a description, not the element itself. The WebElement is the actual handle.
Selenium does not care about visual layout or coordinates, only the DOM structure.
Locators like "first <div> on the page" or "any element with this common class" can easily match the wrong element.
Trying to use findElement everywhere, even when dealing with lists or multiple matches, can cause unnecessary errors.
Forgetting that findElement throws an exception if nothing is found, while findElements quietly returns an empty list.
Jumping straight into coding without fully internalizing DOM → element → locator → WebElement makes everything harder later.