Passing Ranorex object to functions

Ask general questions here.
User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Passing Ranorex object to functions

Post by Aracknid » Thu Sep 29, 2011 7:38 pm

Hi,

I was wondering if what I was doing was smart or efficient, or if there was a better way.

I created a function to click on a ranorex object type, such as an InputTag or an ImgTag, when I pass it in.

My click function is declared as such: Function Click(MyControl as Ranorex.Unknown)

When I'm in another function and I declare an object, such as Ranorex.ImgTag, and I assign something to it, when I want to click on it I call my click function as follows: click(MyImgTag.As(of Ranorex.Unknown))

This works, but I'm wondering if there is a way I can just pass the object without converting it to unknown, since I often forget to do it and it's annoying to do? Obviously if I don't convert it it won't compile.

Another thing I've noticed, is I can decalre my click function as such: Click(MyControl as Ranorex.Core.Element). This allows me to pass in anything without converting it first to unkown and allows me to do some basic things, like check if it's visible. But I cannot do more specific things like click on it unless I convert the element to something specific using Adapter.Create.

FYI: I have my own click function (and other functions like this) because I need to do work to figure out if it's visible and if I should scroll it into view)

Thanks,

Aracknid

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Passing Ranorex object to functions

Post by sdaly » Fri Sep 30, 2011 8:17 am

Can you try changing the parameter type to Ranorex.Adapter?

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Passing Ranorex object to functions

Post by Aracknid » Thu Oct 06, 2011 10:26 pm

Yes, that worked. Thanks.

I find it confusing to know when to use Ranorex.Adapter, Ranorex.Core.Element, Ranorex.Unknown, or just a specific adapter...

Aracknid.

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Passing Ranorex object to functions

Post by artur_gadomski » Tue Oct 11, 2011 9:45 am

Maybe it's because I mainly work with Window Forms but I never use Element for anything. And if I see Unknown I get worried because that generally meant Ranorex had problems detecting something. In most places I use specific adapters because I want to perform a specific actions i.e. expand a tree, click a button.

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

Re: Passing Ranorex object to functions

Post by Support Team » Tue Oct 11, 2011 12:23 pm

Hi,
And if I see Unknown I get worried because that generally meant Ranorex had problems detecting something.
If your controls are recognized as "Unknown" or "Element", Ranorex cannot assign them a role. You can't use special attributes or actions with these elements, but you can usually still create a path that identifies the element to execute minimally mouse clicks or such minimally actions.
Instances of the element class dynamically implement optional Capabilities, as well as numerous standard properties.
Unknown represents a UI element which cannot be further categorized.


Regards,
Markus
Ranorex Support Team