Selenium: How to use stored value in a javascript comparison

Posted by dstrube on Stack Overflow See other posts from Stack Overflow or by dstrube
Published on 2010-01-20T21:11:21Z Indexed on 2010/04/07 19:03 UTC
Read the original article Hit count: 240

Filed under:
|

I've searched around for the answer to this and found lots of much more complicated questions, but none that gave me insight enough to figure this one out.
What I'm doing:
1- open a page with a number that will probably be large
2- get the X Path to where that number is and store it to a variable
3- do a javascript to compare the above stored variable to see if it is bigger than 10, if so, set a new varaible to true; else false (because that is the default value)
4- verify the variable in #3 is true

Sounds simple enough, no?

Where it goes wrong:
At step 3, comparing the variable from step #2 to 10 isn't allowed, at least not the way I'm writing it.

Why?

Details:

<tr>
   <td>open</td>
   <td>http://www.google.com/search?hl=en&q=selenium+verifyEval</td>
   <td></td>
</tr>
<tr>
   <td>store</td>
   <td>/html/body/div[5]/div/p/b[3]</td>
   <td>resultCount</td>
</tr>
<tr>
   <td>storeEval</td>
   <td>var isMoreThan10 = new Boolean(); isMoreThan10 = (resultCount &gt; 10);</td>
   <td>isMoreThan10</td>
</tr>
<tr>
   <td>verifyExpression</td>
   <td>${isMoreThan10}</td>
   <td>true</td>
</tr>

I just thought of one possible workaround: Exapnd the javascript code to get the value there & assign it to a variable there so I'll be more likely to be able to use that variable in the javascript. Not sure exactly how that would be done- anyone wanna help with that?

But surely there is be a better way, isn't there? I must be able to assign a value to a variable in Selenium, then in the next line use that variable in a javascript, right?

© Stack Overflow or respective owner

Related posts about selenium

Related posts about JavaScript