• Selenium Video Tutorials

Selenium IDE - Accessors Commands



Selenium IDE consists of three kinds of commands known as the Actions, Accessors, and Assertions. An accessor command is used to check the application state and then store the outcome in a variable.

How to get the Accessors Command?

We can get hold of the Accesor commands in Selenium IDE, by entering the store within the Command field. Once entered, all the commands related to the store will be available for selection.

Selenium Accessors Commands 1

Example 1

Let us take an example of the below page, where we would enter the text Selenium beside the First Name: label and Tutorialspoint beside Last Name: label. Also, we would obtain the text Selenium - Automation Practice Form using the Selenium IDE taking the help of the Accessors commands.

Selenium Accessors Commands 2

The steps to store variables and access them in Selenium IDE are listed below −

Step 1 − Click on the Selenium IDE extension visible on the browser after its installation.

Step 2 − Selenium IDE should be launched along with it, a welcome message should be displayed with the version of the tool. In the below image, the version installed is 3.17.2.

Along with this, it gives us the option to select what we would like to do with the tool, like Record a new test in a new project, Open an existing project, Create a new project, and Close Selenium IDE.

Also, a link with the text - the Selenium IDE project page is provided, which on clicking would land us to the Selenium Integrated Development Environment documentation page.

https://www.selenium.dev/selenium-ide/

Selenium Accessors Commands 3

Step 3 − Click on the Create a new project link, then enter a project name under the Please provide a name for your new project. Finally, we would click OK.

Selenium Accessors Commands 4

Step 4 − We would have the workspace ready in the Selenium IDE as shown in the below image.

Selenium Accessors Commands 5

Step 5 − Enter open in the Command field, and https://www.tutorialspoint.com/selenium/ in the Target field, to launch the application.

Selenium Accessors Commands 6

Step 6 − Enter store in the Command field, Selenium in the Target field, and i in the Value field. Please note, Selenium is the value we would like to enter using the variable i.

Selenium Accessors Commands 7

Step 7 − Enter type in the Command field, id=firstname in the Target field, and ${i} in the Value field. Please note, id=firstname is the locator value of the input box and ${i} is used to refer to the variable value we would enter using the variable i.

Step 8 − Enter store in the Command field, Tutorialspoint in the Target field, and j in the Value field. Please note, Tutorialspoint is a value we would like to enter using the variable j.

Step 9 − Enter type in the Command field, id=lastname in the Target field, and ${j} in the Value field. Please note, id=lastname is the locator value of the input box and ${j} is used to refer to the variable value we would enter using the variable j.

Selenium Accessors Commands 8

Step 10 − Enter store Text in the Command field, css=div > h1 in the Target field, and k in the Value field. Please note, css=div > h1 is the locator value of the text that we would obtain and k is used to refer to the variable value where we would store the text obtained.

Step 11 − Enter echo in the Command field, ${k} in the Target field. Please note, this would print the text we accessed in Step10 on the web page under the Log in Selenium IDE.

Selenium Accessors Commands 9

Step 12 − Enter store value in the Command field, id=firstname in the Target field, and l in the Value field. Please note, id=firstname is the locator value of the input box and l is used to refer to the variable we would use to obtain the value entered in the input box.

Step 13 − Enter echo in the Command field, ${l} in the Target field. Please note, this would print the value entered in Step7 on the web page under the Log in Selenium IDE.

Selenium Accessors Commands 10

Step 14 − Enter close in the Command field to close the browser window.

Selenium Accessors Commands 11

Step 15 − Click on the three dots appearing at the left pane, then select the Rename option.

Selenium Accessors Commands 12

Step 16 − Enter a name, say TestCase2 under the Rename Test case field, then click on Rename. The entered name would appear on the left of Selenium IDE.

Selenium Accessors Commands 13

Step 17 − Click on the Run all tests from the top, and wait for the test execution to complete. In our example, we would see Runs: 1, Failures: 0, and a green bar denoting the test ran successfully without any failures. Also, the message TestCase2 completed successfully appeared under the Log.

Selenium Accessors Commands 14

In the example above, we obtained the text Selenium - Automation Practice Form which appeared on the web page, and also retrieved the value entered in the input box beside the First Name: label - Selenium under the Log. Besides, we got a green tick beside the test case name - TestCase2 at the top, signifying a passed test.

Apart from that, all the test steps, along with the test case name turned green, reflecting a PASS for all the steps. All the steps which reflected under the Log tab, showed an OK in green.

Thus, in Selenium IDE, we would get the information about the test results both at the test step level and only if all the steps would be executed successfully, we would get a PASS at the test case level as well.

Moreover, we would infer that variables used in one step can be accessed further in other steps using the syntax: ${<variable name>}. In the Steps6, 7, 8, 9, 10, 11, 12, and 13, we followed this approach in our test. Also, we had used store and store related commands like store Text, store Value, and so on to store the variables. The echo command was used to print those values under the Log tab.

Selenium Accessors Commands 15

Example 2

Let us take another example of the below page, where we would capture the page title Selenium Practice - Radio Button taking the help of the Accessors commands.

Selenium Accessors Commands 16

The steps to capture the browser title are listed below −

Step 1 − Follow steps 1 to 4 from the previous example.

Step 2 − Enter open in the Command field, and https://www.tutorialspoint.com/selenium/ in the Target field, to launch the application.

Step 3 − Enter store title in the Command field, and pageTitle in the Value field. Please note, pageTitle is variable to capture the title of the page launched.

Step 4 − Enter echo in the Command field, ${pageTitle} in the Target field. Please note, this would print the text we obtained in Step3 under the Log in Selenium IDE.

Selenium Accessors Commands 17

Step 5 − Follow steps 14 to 17 from the previous example.

Selenium Accessors Commands 18

In the example above, we obtained the page title Selenium Practice - Radio Button under the Log. Besides, we got a green tick beside the test case name - Test6 at the top, signifying a passed test.

Moreover, we would infer that variables used in one step can be accessed further in other steps using the syntax: ${<variable name>}. In the Steps2, and 3, we followed this approach in our test along with the store title command to get the page. The echo command was used to print that value under the Log tab.

This concludes our comprehensive take on the tutorial on Selenium IDE - Accessors Commands. We’ve started with describing how to access Accessor commands in Selenium IDE, and walked through the different Accessor commands like store, store text, store title, and so on and illustrated how to use them along with Selenium. This equips you with in-depth knowledge of the Accessors Commands in Selenium IDE. It is wise to keep practicing what you’ve learned and exploring others relevant to Selenium to deepen your understanding and expand your horizons.

Advertisements