Ranorex Javascript ExecuteScript

Ask general questions here.
crlakshmi
Posts: 4
Joined: Wed Mar 06, 2013 12:19 pm

Ranorex Javascript ExecuteScript

Post by crlakshmi » Wed Mar 06, 2013 1:06 pm

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

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

Re: Ranorex Javascript ExecuteScript

Post by Support Team » Thu Mar 07, 2013 12:54 pm

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)
.
Image

crlakshmi
Posts: 4
Joined: Wed Mar 06, 2013 12:19 pm

Re: Ranorex Javascript ExecuteScript

Post by crlakshmi » Fri Mar 08, 2013 7:26 am

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

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

Re: Ranorex Javascript ExecuteScript

Post by Support Team » Fri Mar 08, 2013 11:29 am

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)
.
Image

crlakshmi
Posts: 4
Joined: Wed Mar 06, 2013 12:19 pm

Re: Ranorex Javascript ExecuteScript

Post by crlakshmi » Fri Mar 08, 2013 1:16 pm

Opening the browser is given in the recording. And while playing the recorded list, the browser is opened before executing the user code.

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

Re: Ranorex Javascript ExecuteScript

Post by Support Team » Mon Mar 11, 2013 9:26 am

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
.
Image

crlakshmi
Posts: 4
Joined: Wed Mar 06, 2013 12:19 pm

Re: Ranorex Javascript ExecuteScript

Post by crlakshmi » Wed Mar 20, 2013 12:31 pm

I was using the 30 days trial version.

Thanks for your response.

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

Re: Ranorex Javascript ExecuteScript

Post by Support Team » Thu Mar 21, 2013 1:47 pm

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)
.
Image