Page 1 of 1

Ranorex Javascript ExecuteScript

Posted: Wed Mar 06, 2013 1:06 pm
by crlakshmi
I need to run a javascript function of the web page from ranorex. So, I gave Add New Action -> User code and, I wrote the following code in Recording1.UserCode.cs

public void greet()
{
WebDocument webDocument = "/doc";
webDocument.ExecuteScript("document.write('Hello World!');");
}


When I play the recording I got the following error in report:

"No element found for path '/doc' within 10s."

What is missing? Or what is the right way to do it?

Thanks in advance

Re: Ranorex Javascript ExecuteScript

Posted: Thu Mar 07, 2013 12:54 pm
by Support Team
Hello,

Your element with the path '/doc' could not be found.
Is it possible to track your element in Spy?

Please try to use the following path for your document:
WebDocument webDocument = @"/dom[@domain='www.ranorex.com' and @caption='Test Automation Tools - Ranorex Automation Framework']";
Regards,
Markus (T)

Re: Ranorex Javascript ExecuteScript

Posted: Fri Mar 08, 2013 7:26 am
by crlakshmi
Thanks for the response, Markus!

I tried with

WebDocument webDocument = @"/dom[@domain='www.ranorex.com' and @caption='Test Automation Tools - Ranorex Automation Framework']";

But still similar error.

This is what i did:

Ranorex studio->Recording(Exisiting recording where browser is opened and some mouse action)->Add new action->User code

In method-> greet

In Recording1.Usercode.cs

There was the function greet created in which I filled as follows:

Code: Select all

        public void greet()
        {
        	WebDocument webDocument = @"/dom[@domain='www.ranorex.com' and @caption='Test Automation Tools - Ranorex Automation Framework']";  
        	webDocument.ExecuteScript("document.write('Hello World!');");
        }
Result:

No element found for path '/dom[@domain='www.ranorex.com' and @caption='Test Automation Tools - Ranorex Automation Framework']' within 10s.



Following is Recording1.Usercode.cs full code:

Code: Select all


///////////////////////////////////////////////////////////////////////////////
//
// This file was automatically generated by RANOREX.
// Your custom recording code should go in this file.
// The designer will only add methods to this file, so your custom code won't be overwritten.
// http://www.ranorex.com
// 
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;

namespace MyJavascriptCode
{
    public partial class Recording1
    {
        /// <summary>
        /// This method gets called right after the recording has been started.
        /// It can be used to execute recording specific initialization code.
        /// </summary>
        private void Init()
        {
            // Your recording specific initialization code goes here.
        }

        public void greet()
        {
        	WebDocument webDocument = @"/dom[@domain='www.ranorex.com' and @caption='Test Automation Tools - Ranorex Automation Framework']";  
        	webDocument.ExecuteScript("document.write('Hello World!');");
        }

    }
}

Is there anything I've missed out or not included or installed?

Thanks,
Lakshmi

Re: Ranorex Javascript ExecuteScript

Posted: Fri Mar 08, 2013 11:29 am
by Support Team
Hello,

Please make sure that the website is open in your browser.
Your code wouldn't open your website.

You might need to add the following code before:
Host.Local.OpenBrowser("http://www.ranorex.com", "IE", "", false, false);
Regards,
Markus (T)

Re: Ranorex Javascript ExecuteScript

Posted: Fri Mar 08, 2013 1:16 pm
by crlakshmi
Opening the browser is given in the recording. And while playing the recorded list, the browser is opened before executing the user code.

Re: Ranorex Javascript ExecuteScript

Posted: Mon Mar 11, 2013 9:26 am
by Support Team
Hi,

Just two questions, which Ranorex version are you using and which browser do you use?
Can you track the page with Spy tool and which RxPath is shown when you do so?

Regards,
Markus

Re: Ranorex Javascript ExecuteScript

Posted: Wed Mar 20, 2013 12:31 pm
by crlakshmi
I was using the 30 days trial version.

Thanks for your response.

Re: Ranorex Javascript ExecuteScript

Posted: Thu Mar 21, 2013 1:47 pm
by Support Team
Hello,

It could be that the website http://ranorex.com instead of http://www.ranorex.com is opened.
This could be the cause for your issue since the domain object is different.

Regards,
Markus (T)