0% found this document useful (0 votes)
36 views3 pages

Locators For Selenium - What Are Locators?

Locators help Selenium find and interact with UI elements on web pages during test automation. As Selenium does not inherently recognize elements, locators provide a way to locate buttons, text boxes, links and other elements. Common locator types include ID, name, class, link text and xpath. Locators are used in test code to find elements like search boxes, buttons and links so Selenium can enter text, click and perform other actions to automate scenarios like searching for a product and adding it to a cart.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Locators For Selenium - What Are Locators?

Locators help Selenium find and interact with UI elements on web pages during test automation. As Selenium does not inherently recognize elements, locators provide a way to locate buttons, text boxes, links and other elements. Common locator types include ID, name, class, link text and xpath. Locators are used in test code to find elements like search boxes, buttons and links so Selenium can enter text, click and perform other actions to automate scenarios like searching for a product and adding it to a cart.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Locators for Selenium – What are

Locators?

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:

1. Buttons
2. Checkboxes
3. Radio Buttons
4. Paragraph Text
5. Menu
6. Menu Option
7. Dropdown field
8. Multi-selection Box field
9. Dropdown field option
10. Text Box Field
11. Text Box Field Label
12. Text Area Field
13. Images
14. Hyperlinks
15. Page Headings
16. 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.
Steps:

1. Navigate to http://tutorialsninja.com/demo
2. Type ‘iPhone’ text into the Search Box field
3. Click on Search Button
4. 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.

You might also like