How to add a loop in Selenium test script

Selenium is a handy tool for web application testing. It provides a test domain-specific language (Selenese) to write tests in a number of popular programming languages, including Java, C#, Groovy, Perl, PHP, Python and Ruby.

Selenium also provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE).

Today we will learn how to add a loop in a test script using Selenium IDE. We have written a selenium core extension using which you can add a loop without knowing any programming language.

  • Download the extension and save. Selenium core extension for loops (Use ‘Save As’)
  • Open Selenium IDE and go to options > options.
  • Add the extension file as Selenium core extension as shown in the picture.
  • Now record your test using selenium IDE. In the example, we have only one command recorded. (open <url>)
  • add following 3 commands before your recorded script.
store 1 y
store 3 x
label target1
  • store 3 x – here 3 is the number of iteration of looping.
  • and at the end of your recorded script, insert following 2 commands
store ${x}-1 x
gotoIf ${y}<=${x} target1
  • Finally the script will look like below.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.