Page 1 of 1

Executing javascript

Posted: Tue Oct 04, 2011 1:12 pm
by Nicklas
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?

Re: Executing javascript

Posted: Tue Oct 04, 2011 1:19 pm
by Todor

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

Re: Executing javascript

Posted: Tue Oct 04, 2011 2:50 pm
by Nicklas
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.