How can I access the second, third.. element of a stored array?

View: New views
5 Messages — Rating Filter:   Alert me  

How can I access the second, third.. element of a stored array?

by Eleo-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If I use "storeSelectedLables" the content of the uses variable looks like "value1,value2".

How can I access one specific element?

I tried ${varname[1]} and ${varname}[1] - both failed.
javascript{storedVars['varname'][1]} showed the second character of the first value.


Has anybody an idea?  

Thanks in advance.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=6839&messageID=19722#19722

---------------------------------------------------------------------
To unsubscribe, e-mail: selenium-ide-users-unsubscribe@...
For additional commands, e-mail: selenium-ide-users-help@...


Re: How can I access the second, third.. element of a stored array?

by Eleo-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here is a simple work around using regex which I tested myself. You may change selectionNo as you wish.
min selectionNo = 0, max selectionNo = <number of labels selected> - 1

Please define selectLocator accordingly.

<tr>
        <td>store</td>
        <td>2</td>
        <td>selectionNo</td>
</tr>
<tr>
        <td>storeSelectedLabels</td>
        <td>${selectLocator}</td>
        <td>selectedArray</td>
</tr>
<tr>
        <td>storeEval</td>
        <td>"${selectedArray}".match("([^,]+,){${selectionNo}}([^,]+)")[2]</td>
        <td>secondLabel</td>
</tr>
<tr>
        <td>echo</td>
        <td>${secondLabel}</td>
        <td></td>
</tr>

Hope this will be helpful.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=6839&messageID=19746#19746

---------------------------------------------------------------------
To unsubscribe, e-mail: selenium-ide-users-unsubscribe@...
For additional commands, e-mail: selenium-ide-users-help@...


Re: How can I access the second, third.. element of a stored array?

by Eleo-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Fascinating... it works! Thanks a lot!

But as I am very curious by nature: could you please explain the regexp to me?

"${selectedArray}".match("([^,]+,){${selectionNo}}([^,]+)")[2]

What I understand:
 ([^,]+,)
take anything that is not a comma and is followed by a comma

{${selectionNo}}
take the "selectionNo"th occurence

([^,]+)
read everything unlike comma

But I don't understeand the meaning of the last "[2]".
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=6839&messageID=19757#19757

---------------------------------------------------------------------
To unsubscribe, e-mail: selenium-ide-users-unsubscribe@...
For additional commands, e-mail: selenium-ide-users-help@...


Re: How can I access the second, third.. element of a stored array?

by Eleo-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> "${selectedArray}".match("([^,]+,){${selectionNo}}([^,]+)")[2]
>
> But I don't understeand the meaning of the last "[2]".

It says which content to be selected. For example
[0] - selects entire match
[1] - selects the content match within first set of parenthesis
[2] - selects the content match within second set of parenthesis (This is what we need).
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.openqa.org/thread.jspa?threadID=6839&messageID=19762#19762

---------------------------------------------------------------------
To unsubscribe, e-mail: selenium-ide-users-unsubscribe@...
For additional commands, e-mail: selenium-ide-users-help@...


Re: How can I access the second, third.. element of a stored array?

by archanab25 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, I want to store an array & access its first element & type it in an input text field

store |  javascript{var array = ["jan","feb"];} | cats
storeEval | "${cats}".match("([^,]+,){${selectionNo}}([^,]+)")[0] || crntmonth
type | month | ${crntmonth}

The second command is giving error.

How can I do this?