How to write an ObjectExists method : Automation API

How to write an ObjectExists method

Class library usage, coding and language questions.

How to write an ObjectExists method

Postby jlowder » Fri Jan 13, 2012 6:31 pm

Hello,

I'm writing all of my automation in Visual Studio 2010, including the declaration of all my objects.

Because I don't have an "ObjectInfo" I can't use .exists. I want to write a method to do so. Currently, for each case I will write something like:

Code: Select all
Ranorex.Button aButton;
var closedButtonExists = Host.Local.TryFindSingle("/form...", 2000, out aButton);
if (closedButtonExists)
{
     aButton.Click();
}


Instead of writing this out each time I want to see if an object exists, I'd like to write a method. But I'm not sure how to pass in a generic type of "object".

Essentially what I'm looking at is:

Code: Select all
public bool ObjectExists(Ranorex.Object myObject, string myXpath)
{
     Ranorex.myObject someObject;
     var doIExist = ...
}


Is this possible? Or is there another way to go about this?

Thanks,

Jason
jlowder
 
Posts: 55
Joined: Wed Dec 30, 2009 3:56 pm

Re: How to write an ObjectExists method

Postby Ciege » Fri Jan 13, 2012 10:35 pm

Maybe try one of the following:
Ranorex.Unknown
Ranorex.Adapter
Ranorex.Core.Element
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...
User avatar
Ciege
 
Posts: 965
Joined: Thu Oct 16, 2008 7:46 pm
Location: Arizona, USA

Re: How to write an ObjectExists method

Postby artur_gadomski » Fri Mar 02, 2012 10:33 am

You can also try to make a generic method:
public bool ObjectExists<T>(string myXpath)
{
     T someObject;
     return Host.Local.TryFindSingle(myXpath, 2000, out someObject);
}
User avatar
artur_gadomski
 
Posts: 125
Joined: Mon Jul 19, 2010 7:55 am
Location: Copenhagen, Denmark


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests