HTML id and name attributes identify elements so WebDriver tests can find, inspect, and manipulate them. Use them as readable locators for semantically significant fields, buttons, and messages. section 10.2.12
Prefer stable, meaningful identifiers when building UI acceptance tests:
- Locate the email field by name="email" and type with sendKeys(). section 10.2.12
- Locate the login button and logged-in user message by unique id values, then click or read their contents. section 10.2.12
- Add unique ids or names to semantically significant elements; use data attributes or other locator strategies when they are more convenient. section 10.2.12
Locating and using an element
driver.findElement(By.id("login-button")).click();
