Selenium IDE User Guide 3 (Control Flow)
Posted May 27, 2020 • 5 min read
The commands included with Selenium IDE allow you to add conditional logic and loops to the test.
This allows you to execute commands(or a set of commands) only when certain conditions in the application are met, or to repeat commands according to predefined criteria.
You can use the
execute script or
\ (# available-commands) available commands
Control flow commands work by specifying open and close commands to represent a set of commands(or blocks).
The following are each available control flow commands and their accompanying commands and/or close commands.
Let us introduce the examples one by one.
\ (# conditional-branching) conditional branch
Conditional branches allow you to change the behavior in the test.
\ (# if-selenium-ide-docs-en-api-commands-if) [
if](/archives/selenium-ide-commands # if)
This is the open command of the conditional block.
If the expression evaluates to
true then the test will execute after it until the next conditional control flow command command(for example,
If the expression evaluates to
false, it will skip subsequent commands and jump to the next relevant conditional control flow command(for example,
\ (# else-if-selenium-ide-docs-en-api-commands-else-if) [
else if](/archives/selenium-ide-commands # else-if)
This command is used in the
if command block.
target input field, execute the command branch that follows it, or jump to the next related control flow command(such as
\ (# else-selenium-ide-docs-en-api-commands-else) [
else](/archives/selenium-ide-commands # else)
else is the final condition you can have in an
if block. If any prerequisites are not met, this command branch will be executed.
After completion, it will jump to the
\ (# end-selenium-ide-docs-en-api-commands-end) [
end](/archives/selenium-ide-commands # end)
This command terminates the conditional command block. Without it, the command block will be incomplete and you will receive a useful error message to let you know when to try to run the test.
\ (# looping) loop playback
Looping allows you to traverse a given set of commands.
\ (# times-selenium-ide-docs-en-api-commands-times) [
times](/archives/selenium-ide-commands # times)
times you can specify a set of commands to be executed for the number of iterations. This number enters the
target input field
times of the command.
To close the
times command block, make sure to use the
\ (# do-selenium-ide-docs-en-api-commands-do) [
do](/archives/selenium-ide-commands # do)
You start this loop from the
do command, then the command to be executed, and then end the
repeat if with the command.
target input field.
do will execute the following command first, and then evaluate the expression
repeat if. If the expression returns,
true then the test will jump back to the
do command and repeat the sequence.
This will continue until the condition returns
false or triggers infinite loop protection-the default is
1000 attempts. You can override this default value by specifying a number in the input field of the
repeat if command.
\ (# while-selenium-ide-docs-en-api-commands-while) [
while](/archives/selenium-ide-commands # while)
while, you want to evaluate in the
target input field. If it evaluates to the
true command block, it will continue to execute until the
end command is reached.
After completion, the test will jump back to the
while command and repeat the same sequence(first check if the condition becomes
To close the
while command block, use the
The loop will retry until the condition returns
false or the infinite loop protection is triggered(default is
1000 attempts). You can override this default value by specifying a number in the input field of the
\ (# foreach-selenium-ide-docs-en-api-commands-for-each) [
forEach](/archives/selenium-ide-commands # for-each)
Trying to do our best, we have the ability to traverse a collection(for example, a JS array) and reference each item in the collection when we perform the process.
target field, specify the name of the variable containing the array to be iterated. In the
value field, specify the name of the iterator variable to use. For each entry in the array, the following command will be executed. During each iteration, the contents of the current entry will be accessed through iterator variables.
\ (# nesting-commands) nested commands
You can nest control flow commands as needed(for example, an
if block can be placed inside a
while block, and vice versa).
\ (# syntax-validation) syntax verification
If you are not sure whether the control flow syntax is correct, try running a test to see. The IDE will find errors in the control flow syntax and call up specific commands that are incorrect or missing.
- Selenium IDE User Guide 1(Crawler Script Recorder)
- Selenium IDE User Guide 2(Command Line Runner)
- Selenium IDE User Guide 3(Control Flow)
- Selenium IDE User Guide 4(Code Export)
- Selenium IDE User Guide 5(FAQ)
- Selenium IDE User Guide 6(Instruction List)
- Selenium IDE User Guide 7(Parameter Definition)