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:
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:
[su_table alternate=”no”]
Command | Target | Value |
---|---|---|
open | http://omayo.blogspot.com/ | |
execute script | return 1 | x |
while | ${x}<5 | |
echo | ${x} | |
execute script | return ${x}+1 | x |
end |
[/su_table]
After incorporating the commands in the above table, our Selenium IDE should look like below:
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)
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 ?
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.
Hi Arun,
thank you a lot for your SeleniumIDE-Tutorial, it’s the best one explaining the new seleniumIDE!
I wonder if it is possible to put seleniumIDE-commands in loops or is it only possible with javaScript expressions? In your example you count a number but i would like to do a “verifyElementPresent” after each count to iterate over rows of a table.
So my example is:
store attribute | xpath=//div[4]/div[2]/[email protected] | rows
execute script | return 0 | count
while | ${count}<${rows}
verify element present | xpath=//tr[{$count}]/td/…
execute script | return ${count} + 1 | count
end
Than you very much.
Regards, philipp