Selenium uses different types of locators to identify the UI elements on the page.
The following is the list of locators based on the priority and recommendations to use:
1. ID
2. Name
3. Link
4. DOM
5. XPath
6. CSS
7. UI-element
i.e. You have to follow the below steps while finding the Locator for the selected UI element:
- First we've to find out if there is any locator which can locate the UI element by ID else you have to go to the next step
- Find out if there is any locator which can locate the UI element by Name else you have to go to the next step
- Find out if there is any locator which can locate the UI element by Link else you have to go to the next step
- Find out if there is any locator which can locate the UI element by DOM else you have to go to the next step
- Find out if there is any locator which can locate the UI element by XPath else you have to go to the next step
- Find out if there is any locator which can locate the UI element by CSS else you have to go to the next step
- Find out if there is any locator which can locate the UI element by UI-element
Why there are different types of locators instead of having only one kind of locator to identify the UI elements ?
While building the application code, it is seen as a good practice to make sure that every element you need to interact with has an ID attribute and a Name attribute. Unfortunately, this best practice is difficult to implement for the UI elements which dynamically change. This is the reason for having different types of locators instead of having only the ID locator to identify the elements.
Please comment below to feedback or ask questions.
How to find out the locators will be explained in the next post.
No comments:
Post a Comment