Store Variables, Echo, Alert, PopUp handling in Selenium IDE
โก Smart Summary
Store commands in Selenium IDE save runtime values into named variables, echo prints them to the log, and a dedicated command family handles alerts, confirmation dialogs and switching between multiple browser windows.
In this tutorial you will learn the store commands, the echo command, and alert and popup handling in Selenium IDE. Together these commands turn a fixed recorded script into one that reacts to whatever the application returns at runtime.
โ ๏ธ A note on versions: the screenshots below come from the original Firefox-plugin Selenium IDE, and the commands use its camelCase Selenese names. The current Chrome, Firefox and Edge extension keeps the same behaviour but writes most command names with spaces. A mapping table appears near the end of this article, and every original command and screenshot is preserved as published.
Selenium IDE Variables
Store
To store variables in Selenium IDE, we use the store command. The illustration below stores the value “tutorial” to a variable named “myVariable.”
To access the variable, simply enclose it in a ${ โฆ } symbol. For example, to enter the value of “myVariable” into the “userName” textbox of Mercury Tours, enter ${myVariable} in the Value field.
Echo Command in Selenium IDE
A stored variable is invisible until something prints it, and that is what the echo command does. It writes a message into the IDE log pane during playback, which makes it the quickest way to confirm that a store command captured what you expected before you build assertions on top of it.
The command accepts either form:
- A literal string. Put the text in the Target field, for example Login step finished, to mark a checkpoint in a long script.
- A variable. Put ${myVariable} in the Target field and the stored value is printed instead of the name.
Two habits make echo far more useful than it first appears. Print a variable immediately after the store command that creates it, so a failure is traced to the capture rather than to the assertion twenty steps later. And prefix each message with the step it belongs to, because the log pane shows every command in one flat list. Note that echo only writes to the log โ it never changes the page and never fails a test, so it is safe to leave in a script permanently.
StoreElementPresent
This command stores either “true” or “false” depending on the presence of the specified element. The script below stores the Boolean value “true” to “var1” and “false” to “var2”. To verify, we will use the echo command to display the values of var1 and var2. The Base URL for the illustration below was set to the Mercury Tours homepage.
StoreText
This command is used to store the inner text of an element into a variable. The illustration below stores the inner text of the h1 tag on the Facebook sign-up page into a variable named “textVar.”
Since it is the only element of its kind on the page, it is safe to use “css=h1” as our target. The image below shows that Selenium IDE was able to save the string “Sign Up” in the “textVar” variable, because echo printed its value correctly.
Alerts, Popup, and Multiple Windows
Alerts are probably the simplest form of pop-up window. The most common Selenium IDE commands used in handling alerts are the following:
| Alerts | Uses |
|---|---|
|
assertAlert assertNotAlert |
retrieves the message of the alert and asserts it against a string value that you specified |
|
assertAlertPresent assertAlertNotPresent |
asserts whether an alert is present or not |
| storeAlert | retrieves the alert message and stores it in a variable that you specify |
| storeAlertPresent | returns TRUE if an alert is present, FALSE otherwise |
|
verifyAlert verifyNotAlert |
retrieves the message of the alert and verifies whether it equals the string value that you specified |
|
verifyAlertPresent verifyAlertNotPresent |
verifies whether an alert is present or not |
Remember these two things when working with alerts:
- Selenium IDE automatically clicks the OK button of the alert window, so you will not be able to see the actual alert.
- Selenium IDE cannot handle alerts that fire inside the page’s onload() function. It only handles alerts that are generated after the page has completely loaded.
In this example we use the storeAlert command to show that even though Selenium IDE did not display the actual alert, it was still able to retrieve the message.
Step 1) In Selenium IDE, set the Base URL to http://jsbin.com. The full URL is http://jsbin.com/usidix. These jsbin snippets date from the Firefox-plugin era and may no longer resolve; any page with a button that raises an alert reproduces the same result.
Step 2) Create the script as shown below. The click command targets the Go! button, storeAlert captures the message into alertMessage, and echo prints it.
Step 3) Execute the script, and do not expect to see the actual alert. The log pane below shows the captured message even though the dialog was never visible.
Confirmations
Confirmations are popups that give you an OK and a CANCEL button, as opposed to alerts, which give you only the OK button. The commands you can use in handling confirmations mirror the alert commands.
- assertConfirmation / assertNotConfirmation
- assertConfirmationPresent / assertConfirmationNotPresent
- storeConfirmation
- storeConfirmationPresent
- verifyConfirmation / verifyNotConfirmation
- verifyConfirmationPresent / verifyConfirmationNotPresent
In addition, these commands tell Selenium which button to choose, OK or CANCEL.
- chooseOkOnNextConfirmation / chooseOkOnNextConfirmationAndWait
- chooseCancelOnNextConfirmation
Place these commands before the command that triggers the confirmation box, so that Selenium IDE knows beforehand which option to choose. Again, you will not see the actual confirmation box during script execution.
Let us test a webpage with a button that was coded to report whether the user pressed OK or CANCEL.
Step 1) In Selenium IDE, set the Base URL to http://jsbin.com. The full URL is http://jsbin.com/enifaf.
Step 2) Create the script as shown below. This time we will press the OK button first.
Step 3) Execute the script and notice that you do not see the actual confirmation, yet the webpage still reports which button Selenium IDE pressed.
Step 4) Replace the chooseOkOnNextConfirmation command with chooseCancelOnNextConfirmation and execute the script again. The page now reports the opposite choice.
Multiple Windows
If you click a link that launches a separate window, you must first instruct Selenium IDE to select that window before you can access the elements inside it. In the legacy IDE you use the window’s title as its locator.
We use the selectWindow command to switch between windows.
We will use the link http://jsbin.com/ocinaj/1, whose title is “First Window.” The “here” hyperlink on that page opens Facebook in a new window, after which we instruct Selenium IDE to do the following:
- Transfer control from the parent window to the newly launched Facebook window using the selectWindow command with the window title as the locator.
- Verify the title of the new window.
- Select the original window again using the selectWindow command with “null” as its target.
- Verify the title of the currently selected window.
The plan above translates into the four-step sequence shown here.
Step 1) Set the Base URL to http://jsbin.com.
Step 2) Create the script as shown below.
We need the pause command to wait for the newly launched window to load before we can read its title.
Step 3) Execute the script. Notice that the test case passed, meaning we were able to switch between windows and verify their titles successfully.
Always remember that setting the selectWindow target to “null” automatically selects the parent window โ in this case the window where the element “link=here” is found.
Note: Facebook has changed its page title since this tutorial was created. Modify the expected title in the script accordingly.
Modern Selenium IDE Equivalents of These Commands
The Firefox-plugin IDE was retired when Firefox moved to the WebExtensions architecture, and the current Chrome, Firefox and Edge extension renamed most Selenese commands to a spaced form. The behaviour is unchanged, so the table below is all you need to read the scripts above against a current install.
| Legacy command in this tutorial | Current Selenium IDE command |
|---|---|
| store | store |
| echo | echo |
| storeText | store text |
| storeElementPresent | store element present (or assert element present) |
| assertAlert / verifyAlert | assert alert / verify alert |
| chooseOkOnNextConfirmation | choose ok on next confirmation |
| chooseCancelOnNextConfirmation | choose cancel on next confirmation |
| selectWindow (title as target) | select window with handle=${handle} |
Two differences are worth calling out. Prompts, which the legacy article does not cover, now have their own commands: answer on next prompt plans the reply before the dialog appears, and webdriver answer on visible prompt types into a prompt that is already open. And window switching no longer relies on the page title. Run store window handle to capture a handle first, then pass handle=${yourHandle} to select window. That change removes the failure mode described in the note above, where a site simply renames its page and the script stops finding the window. The official Selenium IDE project site lists the full current command set.













