简体   繁体   中英

How to use a stored variable and random number with selenium ide

How would a stored variable (stored text) and random number work with Selenium IDE? Trying to do this combination has proved unfruitful.

Example:

<td>type<td>
<td>css=input.some-text</td>
<td>javascript{'storedVars.variable'
    +Number(Math.random(storedVars.rand)*100).toPrecision(2));}</td>

All that is output is storedVars.variable due to the field limit.

Looking for it to return the actual variable value and the random number, ie, text53.

Any help would be greatly appreciated.

You were just off a bit on your usage of storedvars:

<td>javascript{'storedVars.variable'
    +Number(Math.random(storedVars.rand)*100).toPrecision(2));}</td>

Should instead be:

storedVars['variable'] + Numbermber(Math.random(storedVars.rand)*100).toPrecision(2)

More on Randome numbers:

Math.random() returns a decimal number between 0 & 1. so to get a number between 20 & 50 you would do:

Math.random() * (integer range) + (starting number)

Math.random() * 30 + 20

So you would end up with IDE code like this:

<tr>
    <td>storeEval</td>
    <td>Math.random() * 30 + 20</td>
    <td>rand_num</td>
</tr>
<tr>
    <td>echo</td>
    <td>${rand_num}</td>
    <td></td>
</tr>

And then you could use the varible like:

<td>type<td>
<td>css=input.some-text</td>
<td>${rand_num}</td>

OK, I've figured it out.

<tr>
    <td>store</td>
    <td>text</td>
    <td>variable</td>
</tr>
<tr>
    <td>type</td>
    <td>id=lst-ib</td>
    <td>javascript{storedVars.comb=storedVars.variable+Number(Math.random(storedVars.rand)*100).toPrecision(2);}</td>
</tr>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM