Common way to find out, whether control is existing

Ask general questions here.
StuByZurich
Posts: 18
Joined: Fri Jan 23, 2009 2:04 pm

Common way to find out, whether control is existing

Post by StuByZurich » Tue Feb 17, 2009 9:00 am

Hi,

What is the best practice way to find out, whether the element
can be instanciated per xpath??

Should I use the Exists()-Methode?

Thanks for the tip.

Oliver

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

Post by Support Team » Tue Feb 17, 2009 3:49 pm

Well if your test requires the element to exist, it is usually best
to use:

Code: Select all

try
{
    ... find(), automation actions, etc. ...
}
catch(ElementNotFoundException)
{
  .. element was not found ... 
}
If you are looking for a collection of elements, then use the Find() methods
which return a list of adapters or elements.

Validate.Exists(path) is used as an explicit checkpoint which throw ValidationExceptions with a custom message.

There is also an Exists() overload which switches off exceptions and returns "false" instead.

Code: Select all

if (!Exists("/my/element/path", 5000, "", false))
{
   .. element was not found ...
}
Michael
Ranorex Team