The Selenium locators allow its users to access HTML elements from a web page like text boxes, labels, hyperlinks, radio buttons, checkboxes, etc. To check types of locators as you know while writing scripts for automation testing we inserting some input data in the application and verify the results. If you want to learn Selenium you can take up the following Selenium Training Course.
There are many types of Locators which are as follows:-
ID
Name
Link Text
Partial Link Text
Tag Name
Class Name
CSS Selector
XPath
ID locator in Selenium:-
The ID is a well-known locator in Selenium WebDriver, ID gives a unique identity to the element. It helps while writing scripts where multiple choices are existing.
Same as ID, the Name locator can be useful if the ID locator is missing but make sure that every time name attribute cannot be unique.
Talking about Link Text locator so it is used to click on any anchor text. Make sure that anchor text (Link Text) should not be duplicated.
Partial Link Text Locator is the same as Link Text Locator only difference is we can write “Partial Link Text” instead of full link text.
It is mostly used to Check Boxes and Dropdown list.
The ClassName locator can be used if the class name is available. If you are using the rest of the locators there is a chance of duplication.
CSS Selector is really very fast and handy for automation testing. CSS Selector gives multiple choices like:
XPath locator is designed to allow the navigation of XML documents, with the purpose of selecting individual elements, attributes or some other part of an XML document for a specific processing
Type of Xpath locator:
Native Xpath
Relative Xpath
These are the types of locators that help to make automation scripts easy. I hope you will use these types of locators in your work. If you want to explore these more then you must read the following Selenium Tutorial. Here is the video tutorial through which I came to know all about these things. .