Locating Web Elements by id

0 votes

The most common attribute key names are class and id, where id has to be unique over the entire HTML page (according to the HTML specification). This locator strategy allows Selenium WebDriver to find that unique element and perform some action against it.

Example HTML:

<input id="username" type="text" />

We can use one of the following locators:


If we want to be more explicit we can write:


Using the latter we explicitly mention the type of element.


Examine your knowledge and play the ‘locator game‘.

Please follow and like us:
Locating Web Elements by name
Access in-browser Development Tools