Id locator is used to find the web element by the help of id of that element because ID is likely to be unique for each web element.
Id=id of the element
E.g.,- An id can be a username or password in a login page.
Let us see an example of Id locator as a target.
We are creating a login test so that you could get a better understanding of locating elements through Id locator.
- Open the Firefox browser.
- Click on the Selenium icon, and it will open the Selenium IDE interface.
- Now go to the Test Script Editor Box and click on a command text box.
- Write the first command as:-
- This command loads the login page of yahoo on the Firefox browser.
- Then, right-click on the username textbox then,
- click on inspect Element(Q)
- You will get a window contains all the specific codes involved in the Development Tool of the Username text box.
- You have to move the mouse over the developer tools; you will see the highlighted area of the username textbox on the yahoo page.
- Then select the ID attribute that contains the specific ID for the Username text box.
- Now write the second command in selenium –IDE interface:-
- The Username text box is clicked.
- Then we have to enter data in the text box, so for this; we will use the same id element.
- And write the third command as:
- And click on the Run Current Test button.
- It will execute all the inserted commands on the browser.
- The Log pane is displaying the overall summary of the executed test scripts.
- And you can see the executed command results in the Browser as well.