liveBook · Manning

HTML id and name attributes

As explained in BDD in Action, Second Edition

HTML id and name attributes are element attributes that provide identifying or form-related names in an HTML document.

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();

How BDD in Action, Second Edition covers it

How deep it goes
Explains id and name locators with interactions, then defers detailed treatment to data attributes, CSS selectors, and XPath.
Examples
Demonstrates email, login-button, and current-user elements located by name or id.
What it assumes
Assumes basic HTML and WebDriver familiarity while introducing WebElement lookup through findElement().
What you can do after
Apply it via WebDriver to find elements, enter text, click controls, and read displayed text.
How it connects
Connects HTML identifiers with WebDriver, WebElement, data attributes, CSS selectors, XPath, and automated web testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of BDD in Action, Second Edition. The section links point to the parts of the book it draws on.