Behavior of NonExists method

Class library usage, coding and language questions.
User avatar
slavikf
Posts: 104
Joined: Mon Sep 13, 2010 9:07 pm
Location: Toronto, Canada
Contact:

Behavior of NonExists method

Post by slavikf » Tue Nov 30, 2010 2:26 am

I tried to use NonExists method, as follow:
Validate.NotExists(repo.FormSelect_Procedure.SecondRowN,"Actual: There is no 2nd record",false);
But got exception:
Ranorex.ElementNotFoundException: Failed to find item 'FormSelect_Procedure.SecondRowN' within the specified timeout of 1000ms. ---> Ranorex.ElementNotFoundException: No element found for path 'element/element[@controlid='1013']/rawtext[@column='0' and @row='2']'.
--- End of inner exception stack trace ---
at Ranorex.Core.Repository.RepoItemInfo.Find[T](Boolean findSingle, Boolean throwException)
at Ranorex.Core.Repository.RepoItemInfo.CreateAdapter[T](Boolean throwException)

I expected, that method NonExists designed to handle situations, when elements doesn't exists and not cause exception. However, found it's not true.
So, can someone explain - do i understand correctly role of NonExists method?
Or is it special case, because i use GDI plug-in for that element? It's XPath:
element/element[@controlid='1013']/rawtext[@column='0' and @row='2']
Also, even as i put "false" argument to Validate.NotExists method - it still throws exception, which stops the script. (i know, i can put Try-catch block, but what the goal of NonExists then?

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

Re: Behavior of NonExists method

Post by Support Team » Tue Nov 30, 2010 9:51 am

The ElementNotFoundException is not thrown by the Validate.NonExists method, but directly from the repository item, since the element is searched when you access the item. Instead you have to pass the corresponding "Info" object to the NonExists method, e.g. "SecondRowNInfo". See following section in the Ranorex User Guide for more info:
http://www.ranorex.com/support/user-gui ... html#c2517

Your code should then look like the following:
Validate.NotExists(repo.FormSelect_Procedure.SecondRowNInfo, "Actual: There is no 2nd record", false);
Additional information on RepoItemInfo objects can be found here:
http://www.ranorex.com/forum/what-s-a-r ... t1263.html

Regards,
Alex
Ranorex Team
.
Image

User avatar
slavikf
Posts: 104
Joined: Mon Sep 13, 2010 9:07 pm
Location: Toronto, Canada
Contact:

Re: Behavior of NonExists method

Post by slavikf » Tue Nov 30, 2010 9:18 pm

Thank you.
That '*info' object solved issue completely. :D