while (expression), endWhile() - Selenium IDE command

The part between while (expression) and endWhile is executed as long as the expression is true. For sample expressions see also storeEval. If the he expression is false, the IDE executes the immediate next command after endWhile.

Flow control is a built-in Kantu Selenium IDE feature. In the classic Selenium IDE you can add support for flow control by installing the Flow Control plugin.

While_V2 uses executeScript_Sandbox

UI Vision Selenium IDE++ (Kantu) V5.0 uses executeScript_Sandbox to evaluate the expression. The old "While" continues to use storeEval. Please read here about the difference.

In the macro source code the new version of WHILE is "Command": "While_v2". The old version continues to use "Command": "While" for backward-compatibility.

And the new version of "While" uses end instead of endWhile.

while/end Example

The example below is very basic. Best if you see the while/end loop in action by running the DemoCsvSave macro that installs with the IDE. DemocsvSave uses while to loop over all cells in a table row and extract their values.

Command Target Pattern/Text
open https://ui.vision/
while 100 > 5
echo This command is never reached!

while/endWhile Example 2 (Recreate FOR/NEXT Loop)

In this example we use the while/endWhile construct to loop 5 times. Note that storeEval is used to increment the loop counter in each while loop.
Use WHILE/endWHILE to loop 5 times

Works in

Kantu for Chrome Selenium IDE, Kantu for Firefox Selenium IDE, Firefox IDE Classic

Related Demo Macros

DemoIfElse, DemoCsvSave

The ready-to-import-and-run source code of all demo macros can be found in the Github repository testmacros folder.

See also

gotoLabel, Label, storeEval, Web Automation Extension User Manual, Selenium IDE commands, Selenium IDE Flow Control (SelBlocks), Classic Firefox Selenium IDE.

Anything wrong or missing on this page? Suggestions?

...then please contact us.

Kantu Selenium IDE for Chrome and Firefox - Web Test Automation
Subscribe to the a9t9 automation software newsletter . We'll send you updates on new releases that we're working on.