Selenium IDE Loop Example
Selenium IDE is no doubt a great tool for basic automation purpose. It provides many commands which can be used in our day-to-day automation activities. However it is missing a looping feature out of the box. We can add looping functionality in Selenium IDE by using an extension called Flow Control. In this post, we will see how we can implement Selenium IDE loop with a simple example.
Google search page is used as an example here. We will see how Flow Control extension can be used to navigate to Google Advertising and About Google pages multiple times. Before we proceed, let’s first of all see how we can configure Flow Control extension with Selenium IDE. Follow below steps for that.
- Download Flow Control JavaScript file from here.
- Open Selenium IDE.
- Navigate to Options–>General tab.
- Locate the downloaded JavaScript file in Selenium Core Extensions section.
- Click OK button.
- Once this extension is configured, you should be able to see goto, gotoIf and while commands in Selenium IDE.
Below image shows Selenium IDE commands to navigate to Google Advertising and About Google pages.
In the image above, label command is used to create label called ‘openGoogle’. At the end of the script, gotoLabel command sends control to label named ‘openGoogle’. Apart from these, below are details of additional commands from Flow Control extension.
- gotoIf | expression – Jump to specified label if expression is true
- while | expression – Loop while expression is true
- endWhile – Indicate the end of a while loop
- push | value | arrayName – Push value onto an array, creating array if necessary
You can also check out below image which shows extensive use of the commands listed above.
We hope the above example would be helpful in understanding how Selenium IDE Loop can be implemented. Let us know your views on this. If you like this article, consider subscribing to our feed.
I’m using Selenium IDE 2.8.0 on Firefox 34.0, but when I use the extension my test case never starts playing. It just stays at the first step: “[info] Playing test case testname”.
If I remove the extension, it starts playing normally, only that (of course) it breaks as soon as it finds a “while” instruction.
The first two lines in my code are:
store
100
counter
while
${counter}<250
(I intend to iterate while counter, starting at 100, is lesser than 250).
@Patricia
every “while”-Condition needs an “endWhile” to close the condition and to get the test case functional running.
Hi All,
I added the js extension file but it is giving an exception on opening Selenium IDE. The error is: Failed to load user-extensions.js: SyntaxError: expected expression, got ‘<'
You must not download the sideflow.js file via right click.
Copy the file content and paste it into an empty text file in the editor of your choice and save it as sideflow.js. This should work!
Awesome! Thank you very much! 🙂
Hi,
I’m using a test suite. Need to jump to a label defined in a further test in this suite.
Example, I define a gotoif in test1, need to jump to label that is defined in test4.
Is there anyway to do this ?
thanks alot this is help full but you have to mentioned about all jars or pom dependencies, as XML dependency is required.
I am not able to run my script 1000 times
Is there any limitations?
How to run it 1000 times?
Below i am writing my script.
Can you please tell me is there any error in that
getEval
index =0;
while
index <1000;
This is where a basic understanding of coding helps. All you have to do is insert this row BEFORE your steps that you want to loop….
Command: while
Target: true
Then insert this row AFTER your steps that you want to loop…
Command: end
Target: (blank)
Keep in mind, you’ll probably need to add some “waits” in your looping steps somewhere since it will more than likely execute faster than you expect once you configure this.
Dear Connor. I am facing a problem with repeat if for a dropdown menu. Can you help me?