Better way to find objects on screen?

Ask general questions here.
jlowder
Posts: 55
Joined: Wed Dec 30, 2009 2:56 pm

Better way to find objects on screen?

Post by jlowder » Wed Jan 06, 2010 10:33 pm

Hello,

I want to write a while object exists loop but am having difficulty in figuring out the proper mechanisim to do it with this tool. I can't use while object.exists or even while validate.exists(object) and checking to see if the object is null seems to have no impact. Most test tools have some kind of object.exists method to determine if the object is present on the screen. How do I go about this?

I currently use this code:

bool somevar = true;
while (somevar == true)
{
try
{
repo.Gen2Interface.ScrubbingTab.ScrubbersList.scrubberName.Click();
repo.Gen2Interface.ScrubbingTab.ScrubbersList.DeleteScrubber.Click();
Delay.Milliseconds(2500);
}

catch (Exception e)
{
somevar = false;
}

}


The problem with this is that it throws a warning about not finding the object (I expect it) and I get a complaint about not using e. I have no desire to do anything with the failure once it happens..

Suggestions?

Thanks,

Jason

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Better way to find objects on screen?

Post by Support Team » Thu Jan 07, 2010 11:39 am

Hello jlowder!

In Ranorex 2.0 there`s a Search Timeout property to set the time how long you want to search for an element. If the element wasn`t found an ElementNotFound exception is thrown.

Further if you want to check without throwing an exception (as i think in your case) you can use the Exists() method in the ElementInfo instance within the repository, e.g. repo.Gen2Interface.ScrubbingTab.ScrubbersList.scrubberNameInfo.Exists().

Best Regards,
Christian
Ranorex Team
.
Image

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

Re: Better way to find objects on screen?

Post by jlowder » Thu Jan 07, 2010 2:34 pm

Hello Christian,

Thank you. That works.

Jason