Locators of Selenium

Home  >>  Software Testing  >>  Selenium Testing  >>  Locators of Selenium

Locators of Selenium

On August 13, 2019, Posted by , In Selenium Testing, With No Comments

Locators of Selenium

In the previous chapter we learned introduction of Selenium Testing.

Before understanding locators lin Selenium let’s try to understand UI elements. Elements are nothing but fields / labels that are displayed on your application.

Best Selenium Online Training

Our Trainer Profile 

Most of the application will have below common fields / labels:

  1. Text field
  2. Drop-down
  3. Button
  4. Check box
  5. Hyper link
  6. Radio button
  7. Label text
  8. Image

When we talk about testing we have to perform some actions on above fields like entering data, clicking on a button, clicking on a hyper link etc..We generally do all these actions when we do manual testing.

But what if we wanted to do through automation testing? We need to identify these fields I mean properties of the field / image / label in order to perform some action on them through automation testing

So we need to identify locators of the above fields / labels in order to perform some actions on them as part of automation testing

Locators are common in any automation testing and this is common future in all the automation tools in the market. Every tool has its own locators and identifing above fields / labels. We will understand what are the different type of locators available in Selenium in detail except Xpath as we have written seperately in details. Please refer Xpath in selenium

Selenium identifies these using below locators:

  1. ID
  2. NameLocators of Selenium Testing
  3. Link text
  4. Xpath
  5. CSS selector

Before stating identifying them let’s try to understand what are the tools / add on’s available to use them. Below are the few which can be used for identifying the locators(we will discuss about them in another chapter)

  1. Firebug
  2. FirePath
  3. XpathChekker

Learn Selenium Automation Testing Online

Let’s discuss each one of the locators in Selenium detail:

  1. ID: is one of the property which is given for fields. But it is not mandatory that all the fields will have ID. Whenever we ID is available for specific filed then we try to identify a particular field using ID.

Let’s try to understand how we can identify ID value for “Name” field from below screen:

locators of selenium training

Steps:

  1. Open https://www.techtrainersonline.com/contact-us/
  2. Press F12 from your keyboard to open developer console and you will see below screen once you press F12:locators of selenium online training
  3. Now click on icon which is shown on developer consolelocators of selenium online training
  4. Now click on “Name” field and you see below screen which is showing properties of that “Name” field:software testing online training
  5. Here Id value for name field is: iphorm_1_1_5d4f8b2d81801

That’s all as simple as

  1. Name: is also another property for fields which is available. However it is not mandatory to have name property for field.

Let’s try to understand how we can identify Name value for “Email address” field from below screen:

software testing online training

Steps:

  1. Open https://www.techtrainersonline.com/contact-us/
  2. Press F12 from your keyboard to open developer console and you will see below screen once you press F12:selenium automation testing
  3. Now click on icon which is shown on developer console

locators of selenium online training

  1. Now click on “Email address” field and you see below screen which is showing properties of that “Name” field:selenium automation testing online course
  2. Here Name value for Email Address field is: iphorm_1_2

 

  1. Link Text: is also another property for fields which is available. However this property will be available only for hyperlinks on your application

Let’s try to understand how we can identify hyperlink for“About US” from below screen:

Steps:

  1. Open https://www.techtrainersonline.com/
  2. Press F12 from your keyboard to open developer console and you will see below screen once you press F12:
  1. Now click on icon which is shown on developer consolelocators of selenium online training

4. Now click on “About Us” link from above and you see below screen which is showing properties of that “About Us” field:

selenium automation testing online course

Generally all the links on web page will be in anchor tag like <a  text /a>. In above example it is <a href: https://www.techtrainersonline.com/about-us/”/>

Best Selenium Online Training

Our Trainer Profile 

 

Leave a Reply

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