In this tutorial you are going to learn how to use JavaScript blocks in your scripts as well as how to move data within your script using variables.
verifyEval | javascript{1+1} | ${total} .
I have created an example script here for you.
type | element_id | javascript{1+1}
Lets now move on to calling functions that are on the page. This is done by referencing the Selenium JavaScript API. In the last section you were asked to create a script that would type in today's date. In this tutorial I would like you to create a script that will call the JavaScript function that I created to check your input.
To do this you will need to create a reference to the selenium javascript API and work within the current window. From there you
need to call the function that I created. The name of the function is checkDate and has an input of a date value in the format dd/mm/yyyy.
Your command should look a lot like getEval | javascript{ this.browserbot.getCurrentWindow().checkDate('dd/mm/yyyy').
I have created a working version of the script here for you to check your script against.
I am sure that you are now wondering why you would ever want to ever call javascript functions that are on the page. The answer is that sometimes Selenium can't always interact with items on the screen. The latest example I have of this is working the Telerik RadEditor. When it is in its rich text mode Selenium can't actually do anything on the text area but can reference the Editor's API and manipulate the "text area" by calling its getHTML and setHTML functions.
Thank you for using this tutorial and i hope that you found it useful!