Before I start explaining about Locators, we have to first understand the UI Elements?
What are UI Elements?
UI Elements can be anything that is displayed on the Applications. The following are the different examples for UI Elements:
- Radio Buttons
- Paragraph Text
- Menu Option
- Dropdown field
- Multi-selection Box field
- Dropdown field option
- Text Box Field
- Text Box Field Label
- Text Area Field
- Page Headings
- And so on
Let me practically show you different UI elements on the Web Application Page:
As we are now clear with UI Elements, now let’s understand Locators.
What are Locators?
Selenium is by default blind, as it doesn’t have any inbuilt capability or mechanism to locate any UI elements on the Web Pages.
In order to find UI elements on the Web Page, Selenium has to take the help of Locators.
Let’s take an example:
Example: Automate Searching ‘iPhone’ at http://tutorialsninja.com/demo application and add it to cart from the displayed search results.
- Navigate to http://tutorialsninja.com/demo
- Type ‘iPhone’ text into the Search Box field
- Click on Search Button
- In the displayed iPhone Search result, click on the ‘Add To Cart’ option
If we have to automate the scenario mentioned in the above example, Selenium cannot find or locate any of the UI elements required to automate i.e. Search Box field, Search Button, ‘Add To Cart’ option to perform click or type operations.
Selenium will take help of Locators in finding these UI elements which are required for automating the above example scenario. Using Locators, we will be creating locator for each and every UI element required and pass it to the Selenium Test Automation code.
Hence Selenium takes help of these locators for finding the UI elements on the web pages.
Hoping that you understood the role of locators in Selenium Automation, I will explain more about locators, their types, their priorities, practical examples, etc. in the upcoming articles.
- > To learn more about Selenium, continue to the next post (Click on Next Post link below)
- > Check complete Selenium Tutorial Contents here (Click here)
Please leave your questions/comments/feedback below.
Happy Learning ?
On a mission to contribute to the Software Testing Community in all possible ways.