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. Class Name
4. Link
5. CSS
6. XPath
i.e. Theoretically, you have to follow the below steps while finding the Locator for the selected UI element:
- Locate the UI element by using its Unique ID else you have to go to the next step
- Locate the UI element by using its Unique Name else you have to go to the next step
- Locate the UI element by using its Unique Class Name else you have to go to the next step
- Locate the UI element by using its Unique Link else you have to go to the next step
- Locate the UI element by using CSS selector locator else you have to go the next step
- Locate the UI element by using its XPath locator
Practically, most of the people will try to locate the UI element using a unique ID. If unique ID value is not available, they will use CSS selector locator followed by XPath locator.
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, developers may not have provided ID or Name attributes to some elements in your application. So identifying those kind of elements may not be possible if we don't use the other type of locators like XPath or CSS selector locators.
Please comment below to feedback or ask questions.
How to find out the locators using the Selenium will be explained in the next post.
3 comments:
Hi Arun ,
Very Useful and helpful post..
Thank you !
Learn a lot on Selenium.!!
Thank you Arun ... your blog is very nice and easy to understand.
I am enjoying selenium learning.
You have arrange all things very well.
Post a Comment