Selenium ide loop through array variables

in selenium ide, I have built a test case where an array variable stores values. I used a while loop to print these array variables.

enter image description here

here i used "getEval | myarray [0]" to print the first value, which is "postgresql". but no value specified. no error occurs.

[info] Executing: |getEval | myarray = new Array('postgresql','mysql'); | |
[info] script is: myarray = new Array('postgresql','mysql');
[info] Executing: |getEval | index=0; | |
[info] script is: index=0;
[info] Executing: |while | index < myarray.length; | |
[info] Executing: |getEval | myarray[0] | mynewvalue |
[info] script is: myarray[0]
[info] Executing: |echo | ${mynewvalue} | |
[info] echo: ${mynewvalue}
[info] Executing: |getEval | index++; | |
[info] script is: index++;
[info] Executing: |endWhile | | |
[info] Executing: |while | index < myarray.length; | |
[info] Executing: |getEval | myarray[0] | mynewvalue |
[info] script is: myarray[0]
[info] Executing: |echo | ${mynewvalue} | |
[info] echo: ${mynewvalue}
[info] Executing: |getEval | index++; | |
[info] script is: index++;
[info] Executing: |endWhile | | |
[info] Executing: |while | index < myarray.length; | | 

      

now again in the same test case, I changed "getEval | myarray [0]" to be "getEval | myarray [$ {index}] to list the array values ​​by loop index.

enter image description here

now i am getting the following error:

[info] Executing: |getEval | myarray = new Array('postgresql','mysql'); | |
[info] script is: myarray = new Array('postgresql','mysql');
[info] Executing: |getEval | index=0; | |
[info] script is: index=0;
[info] Executing: |while | index < myarray.length; | |
[info] Executing: |getEval | myarray[${index}] | mynewvalue |
[info] script is: myarray[${index}]
[error] Threw an exception: missing ] in index expression 

      

all I need is echo to print "postgresql" and "mysql" are separate newlines. I am very new to selenium plz, helped me solve this problem.

+3


source to share


1 answer


this did the trick for me, hope it helps others too ...

enter image description here

[info] Executing: |storeEval | new Array("postgresql","mysql"); | myarray
[info] script is: new Array("postgresql","mysql");
[info] Executing: |getEval | index=0;
[info] script is: index=0;
[info] Executing: |while | index < storedVars['myarray'].length;
[info] Executing: |storeEval | index | temp
[info] script is: index
[info] Executing: |echo | javascript{storedVars['myarray'][storedVars['temp']]}
[info] echo: postgresql
[info] Executing: |getEval | index++; 
[info] script is: index++;
[info] Executing: |endWhile | | |
[info] Executing: |while | index < storedVars['myarray'].length; | 
[info] Executing: |storeEval | index | temp |
[info] script is: index
[info] Executing: |echo | javascript{storedVars['myarray'][storedVars['temp']]}
[info] echo: mysql
[info] Executing: |getEval | index++; | |
[info] script is: index++;
[info] Executing: |endWhile | | |
[info] Executing: |while | index < storedVars['myarray'].length;

      



Here's the above in the original HTML for cut and paste:

<tr>
<td>storeEval</td>
<td>new Array(&quot;postgresql&quot;,&quot;mysql&quot;);</td>
<td>myarray</td>
</tr>
<tr>
<td>getEval</td>
<td>index=0;</td>
<td></td>
</tr>
<tr>
<td>while</td>
<td>index &lt; storedVars['myarray'].length</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>index</td>
<td>temp</td>
</tr>
<tr>
<td>echo</td>
<td>javascript{storedVars['myarray'][storedVars['temp']]}</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>index++;</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>

      

+6


source







All Articles