Page 1 of 1

How to write an ObjectExists method

Posted: Fri Jan 13, 2012 5:31 pm
by jlowder
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

Re: How to write an ObjectExists method

Posted: Fri Jan 13, 2012 9:35 pm
by Ciege
Maybe try one of the following:
Ranorex.Unknown
Ranorex.Adapter
Ranorex.Core.Element

Re: How to write an ObjectExists method

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