通过数组变量硒IDE环 [英] selenium ide loop through array variables

查看:125
本文介绍了通过数组变量硒IDE环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IDE中的硒,我建立了一个测试案例,其中一个数组变量存储的值。我已经使用whil​​e循环来打印这些数组变量。

in selenium ide, i have built a test case, in which a array variable stores the values. i have used while loop to print those array variables.

在这里,我曾用getEval | myArray的[0]打印第一个值是'PostgreSQL的。但没有列出的值。不会发生错误。

here i have used "getEval | myarray[0]" to print the first value which is 'postgresql'. but the value is not listed. 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; | | 

现在又在相同的测试情况下,我已经改变了getEval | myArray的[0]为getEval |。myArray的[$ {}指数]由循环索引列表数组值

now again in the same test case i have changed the "getEval | myarray[0]" as "getEval | myarray[${index}] to list the array values by loop index.

现在我收到以下错误:

[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 

我需要的是回声打印的PostgreSQL和mysql的是分开的新线路。
我是很新的硒plz帮助我解决这个问题。

all i need is echo to print "postgresql" and "mysql" is separate new lines. i am very new to selenium plz help me to solve this.

推荐答案

这为我做的伎俩,希望它可以帮助别人太...

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

[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;

下面是HTML源代码上面的剪切和粘贴:

Here is the above in Source 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>

这篇关于通过数组变量硒IDE环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆