Selenium Locators

Very basic question what is the locator in selenium, Locators allows us to find elements on a page that can be used in our test.  Actually we need to uniquely identify one element from HTML page where we can do operation like click, select, sendKeys etc.
Selenium webdriver provide us various mechanism to uniquely identify one element from HTML.

1.  Locate elements by ID
2.  Locate elements by Name
3.  Locate elements by Link
4.  Locate elements by Xpath
5.  Locate elements by Css
6.  Locate elements by DOM
7.  Locate elements by PartialLink

Before starting we should begain by making sure that we have all the relevant application installed. While there are not fullproof , they will give us clue how to construct the locator for our test page.

Firefox browser:

1. Firebug: This is a Firefox addon and it allows developer to find elements on the page.

Firebug is available in firefox addon section

firebug install

2. Firepath :

Firepath is available in Firefox addon section.

IE browser:

1. IE Developer tool: This is in build feature for IE ,we can launch by pressing F12.


1. Google chrome developer tool: Like IE this is also in build tool for chrome. By  pressing F12 we can use this tool. We can generate Xpath ,css path using this tool.

find xpath in chrome

copy xpath in chrome
Xapth or css path generation

Now start with locate element by ID

On web application element should have an ID for all there controls on the page. ID should be the unique for that page.

How to find element by ID in selenium 

selenium locators
In the  image you will find the ID of the google search text box.  id="lst-ib".
ID is unique for this page.

Now we will write down java selenium code to uniquely identify the web element (In selenium all web component is a web element) and we will operate on this web element.

Here we are assuming we using Firefox browser
WebDriver driver = new FirefoxDriver();
WebElement we = driver.findElement("st-ib"));

In my next post I will cover below items

1.  Locate elements by Name
2.  Locate elements by Link
3.  Locate elements by Xpath

Share this

Related Posts

Next Post »


September 5, 2017 at 10:41 PM delete

The Locator in the selenium are explained well my sincere thanks for sharing this post Please Continue to share this post
Selenium Training in Bangalore

July 13, 2020 at 9:16 PM delete

Attend The Machine Learning Course Bangalore From ExcelR. Practical Machine Learning course Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Machine Learning course Bangalore.
Machine Learning Course Bangalore

July 27, 2020 at 3:46 AM delete

very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.

Web Designing Training in Chennai

Web Designing Course in Chennai

Web Designing Training in Bangalore

Web Designing Course in Bangalore

Web Designing Training in Hyderabad

Web Designing Course in Hyderabad

Web Designing Training in Coimbatore

Web Designing Training

Web Designing Online Training

August 26, 2020 at 10:19 PM delete This comment has been removed by the author.
March 31, 2021 at 4:14 AM delete

Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more. pareto chart

April 27, 2022 at 7:00 AM delete

I like your post. I appreciate your blogs because they are really good. Please go to this website for Data Science course in Bangalore. These courses are wonderful for professionals.


your ad