In this article, I am going to practically demonstrate the usage of Name locators for locating the UI elements on the Web Pages.
Let’s get started.
Locators for Selenium – Demonstrating Name Locator
Follow the below steps for locating the UI elements on the Web Pages using Name Locator:
1) Install Selenium IDE, if not installed in your chrome browser (Refer steps to install Selenium IDE in your chrome browser)
2) Navigate to http://omayo.blogspot.com/ in your chrome browser as shown below:
3) Right click on the ‘Search’ Text Box field and select ‘Inspect’ option as shown below:
4) Observe that the HTML code related to the ‘Search’ box field got highlighted as shown below:
5) Observe that the above-highlighted HTML code has a name attribute with a value. We can use this name attribute value (i.e. q) as a name locator for locating the ‘Search’ Box field on the Web Page. Lets double click on the name attribute value (i.e. q) of the highlighted HTML line, right-click and select ‘Copy’ option as shown below:
6) Launch Selenium IDE from Chrome Browser by following the steps provided in below article:
7) Enter any Selenium IDE command say ‘Click’ into the ‘Command’ Text box field as shown below:
Note: Without entering this command ‘Find target in Page’ magnifier icon option will be in a disabled state by default and will be enabled only after entering any command into the ‘Command’ text box field as shown below:
8) Now, type name= into the Target text box field as shown below:
9) Paste the name attribute value copied earlier (i.e. in Step 5) into the ‘Target’ Text box field and click on ‘Find target in Page’ search icon option as shown below:
10) Observe that the Search Box field on the Web Page got highlighted for a second on clicking the ‘Find target in Page’ option in the above step using the name=q locator provided in the Target field as shown below:
As the Search box field is getting highlighted using the Name locator (i.e. name=q) provided in Selenium IDE, we can confirm that the give Name locator is able to locate the Search box field using its HTML code’s Name attribute value.
Hence in this example, we have used the Name locator (i.e. name=q) for locating the ‘Search’ box field on the Web Page having the name attribute value as ‘q’.
In the next article, I will demonstrate the next locator i.e. Class Name locator for locating the UI elements on the Web Page.
- > 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.