Page 1 of 1
Common way to find out, whether control is existing
Posted: Tue Feb 17, 2009 9:00 am
by StuByZurich
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
Posted: Tue Feb 17, 2009 3:49 pm
by Support Team
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