Discussion:
How to get array item in Selenium IDE and use it?
c***@public.gmane.org
2013-05-15 12:45:58 UTC
Permalink
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>
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to selenium-users-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/50e3ef50-e48e-4df7-9f22-0b29e1435b4b%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
gilbertf
2013-05-15 13:31:19 UTC
Permalink
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.
Post by c***@public.gmane.org
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>
<tr>
<td>type</td>
<td>name=ProductName[2]</td>
<td>javascript{names['1']}</td></tr>
<tr>
<td>type</td>
<td>name=ProductName[1]</td>
<td>javascript{names[storedVars['rn']]}</td></tr>
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to selenium-users-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/3f6e25e1-da67-495d-84af-0085a5a3f8d2%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
punitha s
2013-05-28 08:30:51 UTC
Permalink
Hi how to compare the two strings with same values using selenium IDE
Post by gilbertf
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.
<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.
Post by c***@public.gmane.org
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>
<tr>
<td>type</td>
<td>name=ProductName[2]</td>
<td>javascript{names['1']}</td></tr>
<tr>
<td>type</td>
<td>name=ProductName[1]</td>
<td>javascript{names[storedVars['rn']]}</td></tr>
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To post to this group, send email to selenium-users-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/06a8a5f8-678e-42ac-a083-11c6513cf2a4%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
Loading...