In this topic, we described about the below sections -
As discussed earlier, Selenium IDE recording follows the user actions and records every user action. Each action on the webpage is stored as a combination of command, target and value. The target value is known as locator of the specific element that is part of the user action.
What is Locator?
Locators are defined as a piece of code that identifies a web element uniquely within the webpage. These locators provide a way to access the HTML elements individually from webpage. Locators are one of the most powerful commands and uses as a basic building blocks of selenium automation scripts.
During the recording, Selenium IDE automatically finds the locator of specific element involved in user action and saves it as a Target value of the action. Finding correct locator is a prerequisite for creating an automation script. However, correct identification of GUI elements manually is more difficult. If the incorrect locator provided in the script, that may lead to script failure. Finding the correct locator is a base for the good script.
A web developer must use a proper and consistent locator scheme to develop a website. Also, a test engineer must choose the correct locator strategy to automate the online workflows.
How to see locators in browser?
As we discussed earlier, finding the correct locator is a base for the good script. So, choosing the correct strategy to find out the locators manually is difficult.
Let us take below example to find out the locator for google search box at google.com. As a first step, open the google.com home page in any browser.
Place the cursor on google search box and right click on it.
Click on “Inspect” command to open the console like below.
The highlighted code in the console are the search box locators in the browser
The below list specifies the different locating Selenium IDE Locating Strategies use in Selenium IDE for locating the UI elements on the web pages -
- Identifier (Not using in latest versions of Selenium IDE)
- Link text
- Partial link text
- Tag name
- Class Name
- XPath Expressions
- CSS Selectors