HomeSelenium

New Selenium IDE – Using ‘while’ command

New Selenium IDE – Using ‘while’ command

Refer the article New Selenium IDE – Commands (Selenese), for the complete list of Selenium IDE commands and their practical demonstrations.

while is one of the commands in Selenium IDE and we can end it with end command.

while is the command in Selenium IDE used for executing a set of same statements multiple times until the while condition becomes false.

In this article, I will execute a set of statements inside the while block multiple times until the while condition becomes false. i.e. I will execute the same set of statements inside the while block until the value inside the variable x is smaller than 5. Initially, I will assign the value 1 to the variable x and thereafter increment the value stored in variable x by 1 until the while condition becomes false (i.e. when the value of x becomes 5, the while condition x<5 will become false).

The while command will work as depicted below:

while Selenium IDE - flow

 

As you can see in the above flow diagram, the block of code inside the while block will be executed multiple times until the while condition become false.

Let’s get started.

New Selenium IDE – Using ‘while’ command

Follow the below steps for practicing while command in Selenium IDE along with me:

1) Let’s create a test in Selenium IDE for printing the value stored in the variable x until the while condition become false as shown below:

Command Target Value
open http://omayo.blogspot.com/
execute script return 1 x
while ${x}<5
echo ${x}
execute script return ${x}+1
end

After incorporating the commands in the above table, our Selenium IDE should look like below:

while Selenium IDE - typing

 

2) Click on ‘Run current test’ option and observe that the test got successfully executed and the value stored in the variable x will be printed multiple times under the Log tab.

Note: The initial value stored in the variable x is 1 (i.e. we have executed JavaScript statement ‘return 1’ as shown above using execute script command, for storing the value 1 into the variable x)

And also, we have incremented the value stored in the variable x by 1 every time we enter into the while block. (i.e. we have executed JavaScript statement ‘return ${x}+1’ as shown above using execute script command, for incrementing the value stored in the variable by 1 every time we enter to the while block)

while Selenium IDE - executed

 

Here concludes the practical demonstration of while command in Selenium IDE.

In the next article, I will practically demonstrate another Selenium IDE command.

Next Steps:

  • > Check complete Selenium Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning 🙂

About Me > Arun Motoori

On a mission to contribute to the Software Testing Community in all possible ways.

Refer the article New Selenium IDE – Commands (Selenese), for the complete list of Selenium IDE commands and their practical demonstrations.

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *