Handling ElementNotFound exception when validating

Class library usage, coding and language questions.
johnzer
Posts: 16
Joined: Thu Aug 18, 2016 9:27 pm

Handling ElementNotFound exception when validating

Post by johnzer » Wed Oct 12, 2016 1:04 am

I'm a little confused about something.

When using Validate.Exists(), we can pass in an Element and a bool specifying whether to throw an exception if the validation fails.

What I don't get is why we can choose to throw an exception or not for this particular case. If it does not find the Element, it will still throw an ElementNotFound exception.

Is there any way to disable or handle the ElementNotfound exception? We have many, many elements to validate and the default message for the Element validation, which explicitly uses the items name, is much better and more informative than the default message for the RepoItemInfo validation, which is 'Self' for all of them.

Thanks.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3949
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Handling ElementNotFound exception when validating

Post by odklizec » Wed Oct 12, 2016 7:56 am

Hi,

I believe your problem could be easily solved by using RepoItemInfo.Exists() with some additional handling what to do in case the element exists/does not exists. See for example this post:
http://www.ranorex.com/forum/validate-e ... tml#p33834
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration