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:
- Text field
- Drop-down
- Button
- Check box
- Hyper link
- Radio button
- Label text
- 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:
- ID
- NameLocators of Selenium Testing
- Link text
- Xpath
- 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)
- Firebug
- FirePath
- XpathChekker
Learn Selenium Automation Testing Online
Let’s discuss each one of the locators in Selenium detail:
- 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:
Steps:
- Open https://www.techtrainersonline.com/contact-us/
- Press F12 from your keyboard to open developer console and you will see below screen once you press F12:
- Now click on icon which is shown on developer console
- Now click on “Name” field and you see below screen which is showing properties of that “Name” field:
- Here Id value for name field is: iphorm_1_1_5d4f8b2d81801
That’s all as simple as
- 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:
Steps:
- Open https://www.techtrainersonline.com/contact-us/
- Press F12 from your keyboard to open developer console and you will see below screen once you press F12:
- Now click on icon which is shown on developer console
- Now click on “Email address” field and you see below screen which is showing properties of that “Name” field:
- Here Name value for Email Address field is: iphorm_1_2
- 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:
- Open https://www.techtrainersonline.com/
- Press F12 from your keyboard to open developer console and you will see below screen once you press F12:
- Now click on icon which is shown on developer console
4. Now click on “About Us” link from above and you see below screen which is showing properties of that “About Us” field:
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