• Selenium Video Tutorials

Selenium IDE - Locating Strategies



Selenium IDE has multiple locating strategies which help to automate test cases. However, Selenium IDE can not identify elements on a web page by default. In order to locate elements, we would need the help of the locators like id, name, css, and xpath.

In addition to the above locators, the older versions of Selenium IDE supported other locators like DOM, and identifier, however, they are deprecated in the latest versions.

Example

Let us take an example of the below page, where we would enter the text Selenium beside the First Name: label. This can be achieved by first locating the elements using various locators.

Selenium IDE Locating Strategies 1

Identify Web Elements

Right click on the webpage, and click on the Inspect button in the Chrome browser, post this action the HTML code for the web page will be accessible. For inspecting an element on a page, click on the left upward arrow as highlighted below.

Selenium IDE Locating Strategies 2

Once we had clicked and pointed the arrow to the input box(highlighted in the below image), its HTML code appeared.

Selenium IDE Locating Strategies 3

Features to Locate Element in Selenium IDE

Once a test would be created after recording in Selenium IDE, we would be able to get the details of any particular step in that test, by clicking on it. Click on the dropdown in the Target field, Selenium IDE while recording successfully captures all the locators like id, name, css, xpath, and so on for an element.

Click on the 4th step, having the values of Command, Target, and Value fields as type, id=name, and Selenium respectively. The other locator values like the name, css, and so on for that element were visible within the Target dropdown.

Selenium IDE Locating Strategies 4

All the steps that we had performed on the application would be recorded in the Selenium IDE under the Command, Target, and Value fields with a REC button to the top right.

The section highlighted below image denotes the Text Script Editor Pane. It has all the user interactions that had been recorded in the form of test steps when the recording was enabled.

Selenium IDE Locating Strategies 5

To identify a web element by default in Selenium IDE, click on the Select target in page button as highlighted in the below image.

Selenium IDE Locating Strategies 6

After clicking the Select target in page button, the user would get the button Select an element on the web page. Once an element is selected, its locator value gets populated by the Selenium IDE.

Selenium IDE Locating Strategies 7

The corresponding locator value of the selected web element was generated in the Target. Then, if the Find target in page button is clicked, the element whose locator value is populated, gets highlighted on the page.

Selenium IDE Locating Strategies 8

Please note that, the buttons - Find target in page, and Select target in page, become enabled only if we have a valid value in the Command field else they remain disabled as highlighted in the below image.

Selenium IDE Locating Strategies 9

Locator ID

The steps to locate the input box using id locator and then enter the text Selenium in Selenium IDE are listed below −

Step 1 − Perform the Steps 1 to 4 of Storing and Accessing Variables.

Step 2 − Enter open in the Command field, and Selenium Automation Practice Form in the Target field, to launch the application.

Selenium IDE Locating Strategies 11

Step 3 − Enter type in the Command field, id=firstname in the Target field, and Selenium in the Value field. Please note, id=firstname is the id locator and its value as firstname for the input box and Selenium is the value to be entered.

Selenium IDE Locating Strategies 12

Step 4 − Enter close in the Command field to terminate the browser.

Selenium IDE Locating Strategies 13

Step 5 − Click on the Run all tests button.

Selenium IDE Locating Strategies 14

In the example above, we entered the text Selenium in the input box using the id locator beside the First Name: label which appeared under the Log. Besides, we got a green tick at the top, signifying a passed test

Locator Name

The steps to locate the input box using name locator and then enter the text Selenium in Selenium IDE are listed below −

Step 1 − Click on the second step created in the above example and enter type in the Command field, name=firstname in the Target field, and Selenium in the Value field. Please note, name=firstname is the name locator, and its value is firstname of the input box and Selenium is the value to be entered.

Selenium IDE Locating Strategies 16

Step 2 − Click on Run all tests, and hold back for the test execution to finish.

Selenium IDE Locating Strategies 17

In the example above, we entered the text Selenium in the input box using the name locator beside the First Name: label which appeared under the Log.

Locator CSS

The steps to locate the input box using css locator and then enter the text Selenium in Selenium IDE are listed below −

Step 1 − Click on the second step created in the above example and enter type in the Command field, css=input#firstname in the Target field, and Selenium in the Value field. Please note, css=input#firstname is the css locator and its value is input#firstname for the input box and Selenium is the value to be entered.

Selenium IDE Locating Strategies 18

Step 2 − Click on Run all tests.

Selenium IDE Locating Strategies 19

In the example above, we entered the text Selenium in the input box using the css locator beside the First Name: label which appeared under the Log.

Locator Xpath

The steps to locate the input box using xpath locator and then enter the text Selenium in Selenium IDE are listed below −

Step 1 − Click on the second step created in the above example and enter type in the Command field, xpath=//input[@id='firstname'] in the Target field, and Selenium in the Value field. Please note, xpath=//input[@id='firstname'] is the xpath locator and its value is //input[@id='firstname'] of the input box and Selenium is the value to be entered.

Selenium IDE Locating Strategies 20

Step 2 − Click on Run all tests at the top.

Selenium IDE Locating Strategies 21

In the example above, we entered the text Selenium in the input box using the xpath locator beside the First Name: label which appeared under the Log.

Conclusion

This concludes our comprehensive take on the tutorial on Selenium IDE Locating Strategies. Weve started with describing an example and walked through the different locating strategies, and illustrated how to use them along with Selenium. This equips you with in-depth knowledge of the locating Strategies in Selenium IDE. It is wise to keep practicing what youve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.

Advertisements