How to check not visible element

Best practices, code snippets for common functionality, examples, and guidelines.
IvanT
Posts: 22
Joined: Wed Feb 06, 2019 8:00 pm

How to check not visible element

Post by IvanT » Mon Feb 25, 2019 8:31 pm

hi. i test desktop app. i need check not visible element and get (true, or false) example:
if (element.enabled){
to do something
}
else{
to do something another
}
but, when i check this element, ranorex throw ElementNotFoundException then i catch it. But it takes too much time. How to do it faster?

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

Re: How to check not visible element

Post by odklizec » Tue Feb 26, 2019 9:57 am

Hi,

I think there is some confusion in your post. The element is expected to be available on page, just made hidden? You see, if the element is not available at all (not even invisible) Ranorex will always search for it the whole effective timeout (timeout of given element) and then, if not found, throw an ElementNotFoundException exception. If you don't want to get the exception and you know for sure the element is usually gone within few seconds, you can use Exists() method, with defined timeout.
        public void CheckIfExists(RepoItemInfo elementToCheck)
        {
        	if (elementToCheck.Exists(10000)) //exists method with search timeout
        	{
        		//if exist, do something
        	}
        	else
        	{
        		//if does not exists, do something else
        	}
        }
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