when to use store vs. storeEval?

690 views
Skip to first unread message

Paul Grandjean

unread,
Oct 24, 2008, 11:18:32 AM10/24/08
to selenium-users...@googlegroups.com
Hi all,

Can someone tell me what are the differences between using +store, storeEval+ and +storeText+?  While trying to use these to resolve a difficult scripting problem, I found myself taking educated guesses.  But they appeared to all do the same thing.

For example,

{font:style=font-family: courier new,courier;}store     javascript{storedVars.index}     getAnchor{font}

vs.

{font:style=font-family: courier new,courier;}storeEval     javascript{storedVars.index}     getAnchor{font}


Don't both of these evaluate the javascript?


Also, what is the different with xpath-locators.  For example.

{font:style=font-family: courier new,courier;}store     //div[@id='resultBox']/table/tbody/tr[1]/td/table/tbody/tr/td/a     getAnchor1{font}

vs.

{font:style=font-family: courier new,courier;}storeEval     //div[@id='resultBox']/table/tbody/tr[1]/td/table/tbody/tr/td/a     getAnchor1{font}

thanks in advance to anyone who can make this clear to me.

Fabien COAT

unread,
Oct 29, 2008, 4:58:21 AM10/29/08
to selenium-users...@googlegroups.com
Hello Paul,

There really is a difference between the two functions:
* +Selenium.prototype.doStore+ in +selenium-testrunner.js+
* +Selenium.prototype.getEval+ in +selenium-api.js+
+store+ only stores an expression, while +storeEval+ evaluates the expression and stores its result.

If you execute the following in the IDE you will easily see the difference:

|| {font:style=color: #ffffff;}*Command*{font} || {font:style=color: #ffffff;}*Parameter1*{font} || {font:style=color: #ffffff;}*Parameter2*{font} ||
| store | alert('hello') | var1 |
| echo | ${var1} | |
| storeEval | alert('hello') | var2 |
| echo | ${var2} | |

The first line does not output anything, and the second line displays "[info] echo: alert('hello')" in the console: there is no evaluation of the expression.
The third line displays a nice alert box with a message 'hello', and the fourth line displays "[info] echo: null" in the console: the expression is evaluated (thus the dialog box), and returns null.

Hope this helps,
Fabien

Reply all
Reply to author
Forward
0 new messages