Types of Locators in Selenium | Selenium Tutorial

Selenium Automation Tool

Selenium locators allow us to access HTML elements from a web page like text boxes, labels, hyperlinks, radio buttons, checkboxes etc. 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.

Types of Locators in Selenium:

  1. ID
  2. Name
  3. Link Text
  4. Partial Link Text
  5. Tag Name
  6. Class Name
  7. CSS Selector
  8. XPath

These are the most useful locators when writing script, in this post we will discuss it one by one.

** You can use Firebug tool to find different attribute of the element on the page

Install Selenium IDE and FireBug

Types of Locators

ID locator in Selenium

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.

Name locator in Selenium

Unlike ID, Name locator can be useful if ID locator is missing but make sure that every time name attribute cannot be unique.

Link Text locator in Selenium

Link Text locator is used to click on any anchor text.  Make sure that anchor text (Link Text) should not be duplicated.

Partial Link Text locator in Selenium

Partial Link Text Locator is like Link Text Locator only difference is we can write “Partial Link Text” instead of full link text.

TagName locator in Selenium

Tag Name locator mostly used for Check Boxes and Dropdown list.

ClassName locator in Selenium

ClassName locator can be used if class name available. If you are using rest of locators there is a chance of duplication.

CSS Selector in Selenium

I hope you know about CSS, It is really very fast and handy for automation testing. CSS Selector gives multiple choices like:

  • Tag and ID
  • Tag and class
  • Tag and attribute
  • Tag, class, and attribute
  • Inner text

Xpath locator in selenium

XPath 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 specific processing

Type of Xpath locator:

  • Native Xpath
  • Relative Xpath

These are the types of locators which helps to make automation scripts easy. I hope you will use these types of locators in your work.

** How to find Xpath using FireFox Browser

Download FireBug add-ons

1.Click on FireBug Icon


2. Click on inspect tool then select any element on the web page to check element’s property.


3. After selecting element -> right click -> select copy xpath option

Xpath locator in selenium













Also, Check:

Leave a Reply

Your email address will not be published. Required fields are marked *