Executing javascript : General Questions

Executing javascript

Ask general questions here.

Executing javascript

Postby Nicklas » Tue Oct 04, 2011 2:12 pm

I need to execute a javascript code within my browser:

Code: Select all
Ranorex.WebDocument webDoc = "/dom[@domain='ourdomain.com']";
webDoc.ExecuteScript("mycode('Age', 25)");


But when I try to run the test I get: Action 'executescript' failed on element '{WebDocument:Untitled page}'. Exception from HRESULT: 0x80020101

Don't seem to be much info/help about ExecuteScript. Could someone please shead some light?
Nicklas
 
Posts: 15
Joined: Mon Sep 26, 2011 3:53 pm

Re: Executing javascript

Postby Todor » Tue Oct 04, 2011 2:19 pm

Code: Select all
webdocument webDoc = "/dom";
webDoc.ExecuteScript("mycode('Age', 25);");


try it like this. And if it doesn't work try altering the exexute line to this:

Code: Select all
webDoc.ExecuteScript("history.back();");


try it again and tell me if it worked or you still get your error
Todor
 
Posts: 66
Joined: Mon Jul 25, 2011 12:28 pm

Re: Executing javascript

Postby Nicklas » Tue Oct 04, 2011 3:50 pm

Thanks for replying quickly. However it seemed the problem layed elsewhere.

When I did the changes you suggested I noticed the test didn't run at all, the report page showed up almost instantly, and with no steps run. After scratching my head for a while I also noticed that in my .cs file (for the recording) all my steps where missing under Run(). When looking in the recording all the steps where there, but when looking in the code my steps where gone:

Code: Select all
[System.CodeDom.Compiler.GeneratedCode("Ranorex", "3.1.0")]
void ITestModule.Run()
{
   Mouse.DefaultMoveTime = 300;
   Keyboard.DefaultKeyPressTime = 100;
   Delay.SpeedFactor = 1.0;

   Init();
}


After deleting the last step in the recording all went back to normal. Strange.

Anyways, now that everything is back to normal ExecuteScript works! Thanks again Todor.
Nicklas
 
Posts: 15
Joined: Mon Sep 26, 2011 3:53 pm


Return to General Questions

Who is online

Users browsing this forum: No registered users and 0 guests