getting the Native Object

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

getting the Native Object

Post by ashishabrol » Tue Feb 08, 2011 11:51 am

Ref: http://www.ranorex.com/support/user-gui ... apter.html

I read in the above post that it possible to access native properties of a .net winform GUI Object.

My question: is it possible to do something similar with /dom GUI element. something like->

Ranorex.WebDocument doc=Host.Local.FindSingle("/dom[@childIndex='0' and @BrowserName='IE']",6000);
Ranorex.Control webdocobj = new Ranorex.Control(doc);

then use the webdocobj to call the dom methods and properties to get the job done.

can you please advice something on it?

thanks

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: getting the Native Object

Post by Support Team » Wed Feb 09, 2011 9:33 am

Hi,

if you'd like to call the dom methods you can invoke javascript methods from your webdocument.
e.g.:
Ranorex.WebDocument doc=Host.Local.FindSingle("/dom[@childIndex='0' and @BrowserName='IE']",6000);
doc.ExecuteScript("history.back();");
Kind regards,
Tobias
Support Team

ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

Re: getting the Native Object

Post by ashishabrol » Thu Feb 10, 2011 12:23 pm

Thanks the reason I was going on the line of getting Native object is because I am dealing with an
application written in .net which uses windows forms. One of the GUI Screen (winform) host a third party component which is an activex component (originally written in MFC).

I need to be able to click/query this object in order to successfully automate the application. Sending MouseClicks at particualr co-ordinates does not work in this case as it fails to induce reliability into the solution. Script fails because of its very nature.

Upon investigation I find that this component has a useful activex API which supports the method that allows the control to be used programatically. but only if you have access to its object at runtime or you must be in-process.Control can be queried for its state and click events sent when necessary.

The issue is in order to send click event I need to have access to the GUI object (via ranorex) and call the related methods as per my convenience.

Is it possible to do so in ranorex? can you send me some samples/info on how this could be done.

thank you!

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: getting the Native Object

Post by Support Team » Thu Feb 10, 2011 3:10 pm

Hi,

here is a sample on how to remotely invoke an a method of a WinForms Control which calls a method of the ActiveX Control.
In this sample a ActiveX controll of VLC Video Player is chosen:
Ranorex.Control elementAxVLCPlugin21 = "/form[@controlname='Form1']/" +
	"element[@controlname='axVLCPlugin21']";
object ret = elementAxVLCPlugin21.InvokeRemotely(
	delegate(System.Windows.Forms.Control ctrl, object inputData)
 	{
  		var ocx = ctrl as AxHost;
  		AXVLC.IVLCControl2 foo = ocx.GetOcx() as AXVLC.IVLCControl2;
  		return foo.VersionInfo;
 	}
);
You have to add a reference to your ActiveX Control.

Regards,
Tobias
Support Team

ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

Re: getting the Native Object

Post by ashishabrol » Fri Feb 11, 2011 11:42 am

Hi

What I am trying to achieve is:

My activex control (Listbar) contains an object SSGroups which has method name 'count' which I can used to query the number of items it contains. In order to invoke the method my code is mentioned below. But it fails. I have addded the reference to the porject.

can you tell me what is wrong. Please let me know incase you need more information from my side.
thanks


Ranorex.Control eleSSListbar="/form[@controlname='Form1']/element[@controlname='ListBar']";
object ret=eleSSListbar.InvokeRemotely(
delegate(System.Windows.Forms.Control ctrl, object inputdata)
{
var ocx=ctrl as AxHost;
Listbar.SSGroups foo=ocx.GetOcx() as ListBar.SSGroups;
return foo.Count;

}
);

Error:
Ranorex.ActionFailedException: Action 'invokeremotely' failed on element '{Unknown:ListBar}'. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Ranorex.Plugin.WinFormsFlavorElement.InvokeMethod(BindingFlags flags, String name, Object[] args)
at Ranorex.Plugin.WinFormsFlavorElement.InvokeRemotely(RemotelyInvokedDelegate deleg, Object inputData)
at Ranorex.Plugin.WinFormsFlavorElement.InvokeAction(Element element, String name, Object[] args)
at Ranorex.Core.Element.InvokeAction(String name, Object[] args)

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: getting the Native Object

Post by Support Team » Fri Feb 11, 2011 9:05 pm

From the exception callstack you can see that a NullReferenceException is thrown in the delegate you pass to the InvokeRemotely method.That means, one of the two "as" statements returns a "null" reference:
var ocx=ctrl as AxHost;
Listbar.SSGroups foo=ocx.GetOcx() as ListBar.SSGroups;
Consequently, either ctrl is not of type AxHost or the object returned by GetOcx() is not of type ListBar.SSGroups. You can check what type the individual variables have using the following code:
object ret=eleSSListbar.InvokeRemotely(
    delegate(System.Windows.Forms.Control ctrl, object inputdata)
    {
        return ctrl.GetType().ToString();
    }
);
Console.WriteLine("Type of ctrl = " + ret.ToString());
Regards,
Alex
Ranorex Team

ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

Re: getting the Native Object

Post by ashishabrol » Mon Feb 14, 2011 7:50 am

the ctrl is of type AxListBar.AxSSListBar. However I cant compile if put this as ctrl type coz AxListBar type/namespace is never found.

I have never done something of this sort so my question might be basic. Apologies if this is the case.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: getting the Native Object

Post by Support Team » Mon Feb 14, 2011 9:17 am

ashishabrol wrote:the ctrl is of type AxListBar.AxSSListBar. However I cant compile if put this as ctrl type coz AxListBar type/namespace is never found.
And what is the error message you receive? Maybe you have to add another assembly that defines that type...

Regards,
Alex
Ranorex Team

ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

Re: getting the Native Object

Post by ashishabrol » Mon Feb 14, 2011 11:07 am

Hi Alex

I figured the missing assembly and can now query the ctrl for it state. However I cant call the needed "fireevent" method to send the click.

here is my error
The event 'AxListbar.AxSSListBar.ListItemClick' can only appear on the left hand side of += or -= (CS0079) - C:\Documents and Settings\Administrator\My Documents\RanorexStudio Projects\SSListBar\SSListBar\Recording1.cs:50,10

can you tell me what I could be missing?

thanks

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: getting the Native Object

Post by Support Team » Mon Feb 14, 2011 1:27 pm

The error tells that ListItemClick is an event, which is fired after the click is preformed, and to which you can add a handler via the += or remove via the -= operators.
You cannot use it to perform the click.

I googled AxSSListBar, and the result (SSListBar) lets me guess, that you are dealing with a Infragistic control. Unfortunately I don't know and didn't find the name of the click method.
This tells you need to set the item's Selected=true;

Regards,
Roland
Ranorex Support Team

ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

Re: getting the Native Object

Post by ashishabrol » Tue Feb 15, 2011 6:38 am

The component has merged into infrafistic but the control is not supported by infragistic yet/anymore.

The control name is sheridan SSListBar.

ListItemClick is an event. When I look at the api of SSListBar ListItemClick it has an argument where it needs ref to object of the Item being clicked.

I have managed to raised this event in VBScript via another automation tool. Where I provide ListItemClick reference to the item which needs clicking.

However in ranorex IDE I don't see this method/event taking any argument here.

Also I dont find ListItem supporting any property which I can set ...Selected=true;

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: getting the Native Object

Post by Support Team » Wed Feb 16, 2011 10:48 am

Hi,

maybe there is a "PerformClick", or a "Click" method for this control you can use.
Maybe it would be a much nicer approach to use Ranorex functionality to perform this click and not the internal.
Otherwise, you can post the VBScript you have used, maybe this will help us solve your issue.

Regards,
Tobias
Support Team

ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

Re: getting the Native Object

Post by ashishabrol » Wed Feb 16, 2011 12:12 pm

Here is vbscript to click on item.

Set obj=Window("Form1").ActiveX("SSListBar").object

Window("Form1").ActiveX("SSListBar").FireEvent "ListItemClick", obj.Groups.item(1).ListItems.item(1)

I have searched a lot in the api and didnt find anything.

I have a dummy application (very small size) which has the control. I can post you if you want.

thanks

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: getting the Native Object

Post by Support Team » Wed Feb 16, 2011 1:51 pm

Hi,

you can either post it in forum or send us an email to [email protected].

Regards,
Tobias
Support Team

ashishabrol
Posts: 13
Joined: Wed Feb 02, 2011 8:05 am

Re: getting the Native Object

Post by ashishabrol » Wed Feb 16, 2011 1:59 pm

attached.
You do not have the required permissions to view the files attached to this post.