How to write an ObjectExists method

Class library usage, coding and language questions.
jlowder
Posts: 55
Joined: Wed Dec 30, 2009 2:56 pm

How to write an ObjectExists method

Post by jlowder » Fri Jan 13, 2012 5: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

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: How to write an ObjectExists method

Post by Ciege » Fri Jan 13, 2012 9: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
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: How to write an ObjectExists method

Post by artur_gadomski » Fri Mar 02, 2012 9: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);
}