• Selenium Video Tutorials

Selenium IDE - Selenese Commands



Every command used in Selenium IDE is known as the Selenese commands. Using the Selenese commands we perform all the testing activities on a web application. Selenese commands are of three types −

  • Actions − The action commands are used to manipulate the state of the application under test. For example, click, type, open, close, and so on.

  • Accessors − The accessor commands are used to assess the state of the application under test and store it in variables. For example, store title, store text, and store value.

  • Assertions − The assertion commands are used to check the state of the application under test. It has three sub-types namely, assert, verify, and waitfor.

Thus Selenese is a language which is used to create test automation using Selenium IDE. We can also define Selenese in Selenium IDE commands. These Selenese commands can be used extensively to test the functionalities of the web applications.

Basic Accessors Commands

The various types of accessors commands are listed below −

  • store(text, variable) − This command is used to store a specific string as a variable.

  • store attribute(locator, variable) − This command is used to store the attribute of the target element with the locator value as a variable.

  • store text(locator, variable) − This command is used to obtain the text of the target element with the locator value and store it in a variable.

  • store title(text, variable) − This command is used to obtain the page title and store it in a variable.

  • store value(locator, variable) − This command is used to store the value of the target element with the locator value in a variable.

  • store window handle(window handle) − This command is used to obtain the window handle id of the current page and store it in a variable.

  • store xpath count(xpath, variable) − This command is used to obtain the total nodes of the given xpath value and store it in a variable.

Basic Assertions Commands

The various types of assertions commands are listed below −

  • assert(variable, expected value) − This command is used to verify if the variable is matching the expected value. The variable is converted to string for comparison. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert alert(alert text) − This command is used to verify if an alert has the text matching the alert text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert checked(locator) − This command is used to verify if the target element with the locator value is checked. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert confirmation(text) − This command is used to verify if a confirmation has been rendered. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert editable(locator) − This command is used to verify if the target element with the locator value is editable. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert element present(locator) − This command is used to verify if the target element with the locator value is available on the web page. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert element not present(locator) − This command is used to verify if the target element with the locator value is not available on the web page. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert not checked(locator) − This command is used to verify if the target element with the locator value is not checked. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert not editable(locator) − This command is used to verify if the target element with the locator value is not editable. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert not selected value(locator, text) − This command is used to verify if the value attribute of the selected option of the target dropdown element does not have the given text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert not text(locator, text) − This command is used to verify if the target element with the locator value does not have the given text.

  • assert prompt(text) − This command is used to verify if a prompt has been rendered. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert selected value(locator, text) − This command is used to verify if the value attribute of the selected option of the target dropdown element has the given text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert selected label(locator, text) − This command is used to verify if the label of the selected option of the target dropdown element has the given text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert text(locator, text) − This command is used to verify if the target element with the locator value has the given text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert title(text) − This command is used to verify if the web page has the given text. If assert did not pass, then the execution will stop at the point of mismatch.

  • assert value(locator, text) − This command is used to verify the value of an edit box. For a radio button/checkbox, the value will be set to on/off provided it is selected or not. If assert did not pass, then the execution will stop at the point of mismatch.

  • verify(variable, expected value) − This command is used to verify if the variable is matching the expected value. The variable is converted to string for comparison. It is a soft assert and execution will not stop in case of a mismatch.

  • verify checked(locator) − This command is used to verify if the target element with the locator value is checked. It is a soft assert and execution will not stop in case of a mismatch.

  • verify editable(locator) − This command is used to verify if the target element with the locator value is editable. It is a soft assert and execution will not stop in case of a mismatch.

  • verify element present(locator) − This command is used to verify if the target element with the locator value is available on the web page. It is a soft assert and execution will not stop in case of a mismatch.

  • verify element not present(locator) − This command is used to verify if the target element with the locator value is not available on the web page. It is a soft assert and execution will not stop in case of a mismatch.

  • verify not editable(locator) − This command is used to verify if the target element with the locator value is not editable. It is a soft assert and execution will not stop in case of a mismatch.

  • verify not selected value(locator, text) − This command is used to verify if the value attribute of the selected option of the target dropdown element does not have the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • verify not text(locator, text) − This command is used to verify if the target element with the locator value does not have the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • verify selected label(locator, text) − This command is used to verify if the label of the selected option of the target dropdown element has the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • verify selected value(locator, text) − This command is used to verify if the value attribute of the selected option of the target dropdown element has the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • verify text(locator, text) − This command is used to verify if the target element with the locator value has the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • assert title(text) − This command is used to verify if the web page has the given text. It is a soft assert and execution will not stop in case of a mismatch.

  • verify value(locator, text) − This command is used to verify the value of an edit box. For a radio button/checkbox, the value will be set to on/off provided it is selected or not. It is a soft assert and execution will not stop in case of a mismatch.

  • wait for element editable(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value to be editable.

  • wait for element not editable(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value not to be editable.

  • wait for element not present(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value to be unavailable on the web page.

  • wait for element not visible(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value to be invisible on the web page.

  • wait for element present(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value to be available on the web page.

  • wait for element visible(locator, wait time) − This command is used to wait for the given wait time(in milliseconds) for the target element with the locator value to be visible on the web page.

Basic Actions Commands

The various types of action commands are listed below −

  • click(locator) − This command is used to click on a link, button, checkbox or radio button.

  • check(locator) − This command is used to check a radio button or checkbox.

  • uncheck(locator) − This command is used to uncheck a radio button or checkbox.

  • choose cancel on next confirmation − This command is used to deal with the next confirmation alert. It will cancel it.

  • choose cancel on next prompt − This command is used to deal with the next alert prompt. It will cancel it.

  • choose ok on next confirmation − This command is used to deal with the next confirmation alert. It will accept it.

  • click At(locator, coordinateString) − This command is used to click on a link, button, checkbox or radio button at a specific location.

  • close − This command is used to close the current window.

  • debugger − This command is used to pause test execution for debugging tests.

  • double click(locator) − This command is used to double click on a link, button, checkbox or radio button.

  • double click at(locator) − This command is used to double click on a link, button, checkbox or radio button at a specific location.

  • drag and drop to object(source locator, destination locator) − This command is used to drag an element from the source locator to the destination locator.

  • echo(message) − This command is used to print the message. It is most commonly used for debugging purposes.

  • edit content(locator, value) − This command is used to enter the value of an editable web element.

  • execute script(script, variable name) − This command is used to execute a JavaScript command within the window or frame in focus.

  • execute async script(script, variable name) − This command is used to execute an async JavaScript command within the window or frame in focus.

  • mouse down(locator) − This command is used to simulate pressing the left mouse button by user(without release).

  • mouse down at(locator, coordinateString) − This command is used to simulate pressing the left mouse button by user(without release) at a specific location.

  • mouse move at(locator, coordinateString) − This command is used to simulate pressing the mouse button by the user at a specific location.

  • mouse out(locator) − This command is used to simulate moving the pointer of the mouse away by user.

  • mouse over(locator) − This command is used to simulate mouse hovering on an element identified by the locator.

  • mouse up(locator) − This command is used to simulate release of the mouse button.

  • mouse up at(locator, , coordinateString) − This command is used to simulate release of mouse button at a specific location.

  • open(url) − This command is used to open a url and wait for the page to load.

  • pause(wait time) − This command is used to stop the execution for some time.

  • remove selection(locator, option) − This command is used to deselect an option in a multi-select dropdown.

  • run(test case) − This command is used to run a test case.

  • select(locator, option) − This command is used to select an option in a dropdown.

  • select frame(locator) − This command is used to select a frame within the window in focus.

  • select window(window handle) − This command is used to select a popup window with the help of the window handle id.

  • set window size(resolution) − This command is used to specify the window size of the browser along with the browser interface.

  • type(locator) − This command is used to enter text in an input box.

Example

Let us take an example of the below page, where we would capture the page title Selenium Practice - Radio Button taking the help of the accessors commands. Then click on the radio button beside the Yes label using the actions commands.

Selenium Selenese Commands 1

After selecting the radio button, we would get the text - You have checked Yes, which we would verify using the assertions command.

Selenium Selenese Commands 2

The steps to be followed 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 Selenese Commands 3

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

Step 4 − We would have the workspace ready in the Selenium IDE now.

Selenium Selenese Commands 4

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

Step 6 − 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 7 − Enter echo in the Command field, ${pageTitle} in the Target field. Please note, this would print the text we obtained in Step6 under the Log in Selenium IDE.

Step 8 − Enter click in the Command field, xpath=/html/body/main/div/div/div[2]/form/div[1]/input in the Target field. Please note, xpath=/html/body/main/div/div/div[2]/form/div[1]/input is the locator value of the radio button.

Step 9 − Enter assert element present in the Command field, xpath=//*[@id="check"] in the Target field. Please note, xpath=//*[@id="check"] is the locator value of the text - You have checked Yes.

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

Selenium Selenese Commands 5

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

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

Step 13 − 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 that the completed successfully appeared under the Log.

Selenium Selenese Commands 6

In the example above, we had launched the application with open command and obtained the page title Selenium Practice - Radio Button under the Log with the help of the store title command. We clicked on the radio button using the click command and verified the text - You have checked Yes with the help of the assert element present command. Besides, we got a green tick beside the test case name - Test9 at the top, signifying a passed test.

This concludes our comprehensive take on the tutorial on Selenium IDE - Selenese Commands. We’ve started with describing a Selenese command, and various accessors, actions, and assertions commands and an example to walk through how to use the Selenese commands along with Selenium. This equips you with in-depth knowledge of the Selenese 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