← Selenium Automation Testing learning pathSelenium Automation Testing · Module 3 of 10
Locating elements
Find elements reliably with locators.
📖 Key ideas
- find_element(By.ID, "email") finds one element.
- Locators: ID, NAME, CLASS_NAME, TAG_NAME, LINK_TEXT, CSS_SELECTOR, XPATH.
- Prefer stable IDs or data-testid attributes.
- CSS selectors are fast and readable.
- 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