How to get array item in Selenium IDE and use it?

877 views
Skip to first unread message

chec...@abv.bg

unread,
May 15, 2013, 8:45:58 AM5/15/13
to seleniu...@googlegroups.com

this is my code

<tr>
    <td>storeEval</td>
    <td>new Array ('cat','dog')</td>
    <td>names</td>
</tr>
<tr>
    <td>storeEval</td>
    <td>javascript{storedVars['names'].length}</td>
    <td>length</td>
</tr>
<tr>
    <td>storeEval</td>
    <td>Math.floor((Math.random()*storedVars['length'])+0)</td>
    <td>rn</td>
</tr>

and here is where it doesnt work:

<tr>
    <td>type</td>
    <td>name=ProductName[2]</td>
    <td>javascript{names['1']}</td>
</tr>

this doesnt work as well (i want to use a random item here):

<tr>
    <td>type</td>
    <td>name=ProductName[1]</td>
    <td>javascript{names[storedVars['rn']]}</td>
</tr>

gilbertf

unread,
May 15, 2013, 9:31:19 AM5/15/13
to seleniu...@googlegroups.com
I'm not sure if javascript arrays would work, but the sequence does not work as is.  There is a quirk in IDE where the variables you create are not directly avaliable in javascript.

If you try changing the two first storeEval like this:

<tr>
<td>storeEval</td>
<td>names = new Array ('cat','dog')</td>
<td>names</td>
</tr>
<tr>
 
<td>storeEval</td>

 
<td>length = names.length</td>
 
<td>length</td>
</tr>

This way, the name variable will be accessible both in selenese and javascript, so the second storeEval has a better chance of doing what you need.

Of course, you could use a selenese variable in your javascript by using the storedVar syntax, but I am not sure you could store objects in those. 
Reply all
Reply to author
Forward
0 new messages