Introduction
Selenium is an automation testing tool where the tester’s job is to write scripts. In Selenium, things are identified using a concept called “locators.” The elements can be located using Selenium’s find element function. An object of the type WebElement is returned once a locator or query object of the ‘By’ type has been provided. The many available locator techniques can be utilised with the ‘By’ entity. Selenium uses locators to recognise the elements on a webpage.
Any automation tool used when building scripts for testing a web application must correctly identify the web components or web objects to carry out the requested action, such as clicking or entering text on the associated web element or object. The term for this is object identification. Links, buttons, text boxes, drop-down selectors, radio buttons, list boxes, sliders, and other objects are used in every application.
To learn more about Locators Used In Selenium for object identification, join Selenium Training in Chennai.
ID
Due to the fact that ID will be distinct for each element, it is the most effective and preferred method of locating online elements on a web page. IDs are the first choice for object identification since they are the safest and quickest way to identify an element.
Driver.findElement(By.id(“Element ID”)), Syntax:
However, IDs may not always be mentioned in the webpage’s HTML codes. You would need to use other locators in such circumstances.
Name
if the element’s ID is not specified, the backup option is. As with IDs, the Name attribute does not always need to be unique, so make sure it is unique on the webpage. There is, therefore, a possibility that other items with the same name exist, and your script may choose the incorrect element as a result.
Driver.findElement(By.name(“Element Name”)), Syntax
Class Name
Another locator for locating web elements is this one. But make sure it is unique if you use the class name to identify elements. Multiple components with the same class name are possible. This locator is frequently used to locate a collection of components belonging to the same class and carry out operations on it.
Driver.findElement(By.className(“Element className”)) is the syntax.
TagName
Here, Selenium searches for the items based on the tag name. For group elements like Select/Checkboxes, drop-down menus, etc., tag names are an excellent option.
Driver.findElement(By.tagName(“Element TagName”)), Syntax.
Selenium Online Training will enhance your testing skills and knowledge about Automation Testing Frameworks in Selenium.
LinkText
The text in a hyperlink that can be clicked is known as the link text. The text between the anchor tags is what it is. Make sure that this is unique as well. Multiple links with the same text may exist, for example, in repeated header and footer menus. Selenium will execute the action on the first element matching the link text if there are many instances.
Driver.findElement(By.linkText(“Link Text”)), Syntax
Conclusion
Now that we have seen the various locators used in Selenium to identify web elements, let’s look at how to use these locators using the findElement() method. How do you obtain the values for these locators now? Not to worry. These days, viewing HTML snippets is relatively simple, thanks to most browser’s built-in browser inspectors.
To learn more about Selenium automation, join Selenium Training in Coimbatore at FITA Academy for the best training with career guidance.
Also, Read the Top 10 Selenium Automation Training Institutes in Chennai.


