Code snippet for ExecuteScript function with return type

Class library usage, coding and language questions.
VijiSrinivasan
Posts: 1
Joined: Mon Aug 19, 2013 2:47 pm

Code snippet for ExecuteScript function with return type

Post by VijiSrinivasan » Mon Aug 19, 2013 3:58 pm

Hi,

I noticed that with the 4.1.0 release Ranorex is providing the ability to have a return value for the ExecuteScript function.
The ExecuteScript method on WebDocuments now returns the value returned by the script
Previously ExecuteScript() just used to execute some function and that didn't return any value. But we wanted to do some manipulations based on the return value of our javascript function execution. Fortunately this new feature is exactly what we want to use as we want to leverage a method in our javascript to find the state of an applet before performing actions in it.

I would like to know the answers to the following:
1. Is it possible to use the webDocument class on a frame? Our application is part HTML and part applet based. And the javascript method I want to leverage is part of the html part of the console.
2. Please provide a sample code snippet with the new syntax with return value for the executeScript method.

Regards,
Viji

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Code snippet for ExecuteScript function with return type

Post by Support Team » Fri Aug 23, 2013 3:52 pm

Hello Viji,

If the script is inside an iframe you have to use the IFrameTag in order to execute the script.
Please find below a little code snippet which shows how to get the return value of a JavaScript method.
Host.Local.OpenBrowser("http://www.w3schools.com/js/tryit.asp?f ... ion_return", "IE");
IFrameTag myIframeTag = @"/dom[@pageurl='http://www.w3schools.com/js/tryit.asp?f ... ion_return']//iframe[#'iframeResult']";
string resultString = myIframeTag.ExecuteScript("return myFunction(4,3);");
Report.Info(resultString);
Regards,
Bernhard
.
Image