← Selenium Automation Testing learning path
Selenium Automation Testing · Module 3 of 10

Locating elements

Find elements reliably with locators.

📖 Key ideas

  1. find_element(By.ID, "email") finds one element.
  2. Locators: ID, NAME, CLASS_NAME, TAG_NAME, LINK_TEXT, CSS_SELECTOR, XPATH.
  3. Prefer stable IDs or data-testid attributes.
  4. CSS selectors are fast and readable.
  5. Avoid fragile absolute XPaths.
💡 Real-life example: Locators are addresses for page elements: a precise address (ID) beats "third house after the tree".
LocatorWay to find an element
CSS selectorPattern selecting elements like CSS
XPathPath expression to elements
data-testidAttribute added for testing