UI Vision Selenium IDE++ (Kantu)
V5.0
: The storeEval command is deprecated. Please use the new
executeScript
.
Old macros with storeEval continue to work without any change.
What is the difference between storeEval and executeScript?
Both commands evaluate Javascript
in the context of the website
. There are three main differences. First, with executeScript
variables are
not
in quotation marks. Second, you need to add a "return" command if you want to return a result. And third,
storedVars
is no longer required.
Example (generate a random number between 0 and ${max}):
storeEval | Math.floor(Math.random()* Number ("${max}") | randomNumber
becomes
executeScript | return Math.floor(Math.random()* Number (${max}); | randomNumber
In addition in the UI Vision's Selenium IDE++ the ExecuteScript command
is available as "sandboxed" version that does
not
run in the context of the website. This fixes a long-standing design issue of the
classic Selenium IDE and avoids CSP errors. For more details see
executeScript_Sandbox
.
--- Old storeEval documentation: ---
The
storeEval
command is useful to run javascript snippets. The command works just
like "getEval" or "runScript" but has the advantage that the result of EVAL is stored in a variable. The result can be, for example,
a time stamp, a random number or an entry from a list. The new IDE does not support "getEval" or "runScript" because storeEval can do the same, just better.
Inside storeEval you can access the value of a variable with the ${BBB} notation. If you want to use the variable itself,
use the
storedVars['BBB']
notation. So this works the same as in the Firefox IDE, even so internally it is very different.
VerifyEval works just like StoreEval, but instead of adding the result to a variable, it compares the result with the value in the 3rd column. It is not available in the
UI.Vision RPA
Selenium IDE, but it can be recreated with storeEval plus
if | ${!LastCommandOK}
... endIf.
See also .
Useful Javascript snippets for use with storeEval/getEval/runScript
Use them like
storeEval | Javascript here | VarWithResult
. Then later in the macro, you can use the result with the
${VarWithResult}
variable.
Javascript
Result
Math.floor(Math.random()*11)
Random number between 0 and 10
x="abc"; x.length;
Returns the length of the string (here 3). You see that always the value of the last command is returned by storeEval.
var audio = new Audio('http://www.storiesinflight.com/html5/audio/shimmer.wav');audio.play();
Play sound!
x="${myvar}"; x.length;
Same as above but with variable as input.
Note that our variable ${myvar} is converted
to a text
string before the Javascript EVAL is executed. Therefore ${myvar} has to be inside "..." like any other text.
var d= new Date(); var m=((d.getMonth()+1)<10)?'0'+(d.getMonth()+1):(d.getMonth()+1); d.getFullYear()+"-"+m+"-"+d.getDate();
Get todays date in YYYY-MM-DD format
var d= new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * 5); var m=((d.getMonth()+1)<10)?'0'+(d.getMonth()+1):(d.getMonth()+1); d.getFullYear()+"-"+m+"-"+d.getDate();
Get yesterday's date (-1), tomorrows date (1) or the date in 5 days (5) => Just change the number
5
in the code snippet
(new Date().getHours()+" : " + new Date().getMinutes() + " : " + new Date().getSeconds())
Get current time
Works in
UI.Vision RPA
for Chrome
Selenium IDE
,
UI.Vision RPA
for Firefox
Selenium IDE
,
Firefox IDE Classic
Related Demo Macros
DemoStoreEval
The ready-to-import-and-run source code of all demo macros can be found in the
Open-Source RPA software
Github repository.
See also
storedVars
,
storetext
,
storetitle
,
Web Automation Extension
User Manual,
Selenium IDE commands
,
Classic Firefox Selenium IDE
.
Anything wrong or missing on this page? Suggestions?
...then please
contact us
.