Can't get Selenium IDE Nested Loop to work

840 views Asked by At

I'm trying to make a very simple script with a nested while loop in Selenium IDE which will eventually be used to print all elements in a matrix.

I start by initialising two variables 'i' and 'j' to 0, I then start the first loop to run while i<3, I then start another loop to run while j<3 inside this loop and increment each at the end of each loop.

The numbers printed should read; 0 0, 0 1, 0 2, 1 0, 1 1, 1,2, 2 0, 2 1, 2 2

However I only seem to be able to complete the inner loop once, so am only getting: 0 0, 0 1, 0 2

Thee code I am using is here;

<tr>
    <td>store</td>
    <td>0</td>
    <td>i</td>
</tr>
<tr>
    <td>store</td>
    <td>0</td>
    <td>j</td>
</tr>
<tr>
    <td>while</td>
    <td>${i} &lt; 3</td>
    <td></td>
</tr>
<tr>
    <td>while</td>
    <td>${j} &lt; 3</td>
    <td></td>
</tr>
<tr>
    <td>echo</td>
    <td>${i} ${j}</td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>new Number(storedVars['j'])+1</td>
    <td>j</td>
</tr>
<tr>
    <td>endWhile</td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>storeEval</td>
    <td>new Number(storedVars['i'])+1</td>
    <td>i</td>
</tr>
<tr>
    <td>endWhile</td>
    <td></td>
    <td></td>
</tr>

Does anyone know how to fix this or have a work around? I assume the issue comes from losing the variable at the end of a loop however I'm not sure, this would be so easy in C!

Thanks, J

1

There are 1 answers

0
Daniel Perez On

You can try a workaround using nested gotoIf/label

"Command": "label",
"Target": "Loop1",

(increase count1)
   
 "Command": "label",
 "Target": "Loop2",
 
  "Command": "echo",
  "Target": " ${count1}, ${count2}",
   
  (increase count2) 
 "Command": "gotoIf",
 "Target": "${count2} < 3",
 "Value": "Loop2"  
 
(reset count2) 
 
"Command": "gotoIf",
"Target": "${count1} < 4",
"Value": "Loop1"