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.

  • ๐Ÿ”˜ Create a variable: The store command takes the value in Target and the variable name in Value.
  • โ˜‘๏ธ Read it back: Wrap the name in ${ } wherever a command accepts a target or a value.
  • โœ… Print for debugging: echo writes a literal string or a variable straight into the IDE log.
  • ๐Ÿงช Alerts are auto-accepted: The IDE clicks OK for you, so use storeAlert to capture the message text.
  • ๐Ÿ› ๏ธ Confirmations need a decision: Place chooseOkOnNextConfirmation before the command that opens the dialog.
  • ๐Ÿ“Š Window switching: selectWindow targets a window title, and a null target returns to the parent window.

Store variables, echo, alert and popup handling in Selenium IDE

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.”

Selenium IDE store command with the value tutorial saved into 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.

Selenium IDE type command using ${myVariable} in the Value field of the userName textbox

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.

Selenium IDE storeElementPresent saving true to var1 and false to var2, echoed in the log

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.”

Selenium IDE storeText command reading css=h1 into the textVar variable

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.

Selenium IDE log pane printing Sign Up as the value stored in textVar

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.

Selenium IDE script with click, storeAlert and echo commands against the jsbin alert demo page

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.

Selenium IDE log showing the alert text retrieved by storeAlert after playback

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.

Selenium IDE script placing chooseOkOnNextConfirmation before the click that opens the dialog

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.

Test page reporting that the OK button of the confirmation dialog was pressed

Step 4) Replace the chooseOkOnNextConfirmation command with chooseCancelOnNextConfirmation and execute the script again. The page now reports the opposite choice.

Selenium IDE script edited to use chooseCancelOnNextConfirmation instead of chooseOkOnNextConfirmation

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.

Diagram of the switch from the parent window to the new window and back again

Step 1) Set the Base URL to http://jsbin.com.

Step 2) Create the script as shown below.

Selenium IDE script using selectWindow, pause and verifyTitle to move between two windows

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.

Green passing result in Selenium IDE after both window titles were verified

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.

FAQs

Yes. ${myVariable} and ${myvariable} refer to two different variables, and referencing one that was never stored resolves to an empty string rather than raising an error. Keep a single naming convention across a suite to avoid silent blanks.

Yes. The ${ } syntax is expanded in any Target or Value field, so it works inside an open command, an XPath or a CSS selector. That is how a recorded script is turned into one driven by data captured earlier in the run.

Selenese has no maths operators. Use the execute script command with a small JavaScript expression that reads the variable and returns the result, then store that return value. Remember every stored value arrives as a string, so convert it first.

Treat them as local to a single test. Relying on a value set by an earlier test makes the suite order-dependent and hard to debug, so store what a test needs inside that test, or read it from a data file at the start.

A prompt needs text, not just a button choice. Run answer on next prompt with the reply in the Value field before the command that opens it, or use webdriver answer on visible prompt when the dialog is already on screen.

Machine learning tools can propose a command sequence from a plain-language description of a scenario and suggest sturdier locators than a recorder produces. AI-assisted locator repair also helps, since a renamed element is the usual reason a stored value comes back empty.

Yes. Export the test to Java or Python, then let Copilot refactor the flat command list into page objects and reusable waits. Check the alert handling by hand, because generated code often assumes a visible dialog that the IDE already dismissed.

Title-based selection becomes ambiguous and the wrong window may be chosen. This is exactly why the current IDE prefers handles: capture one with store window handle right after the window opens, then switch with handle=${yourHandle}.

Summarize this post with: