How to check not visible element

Best practices, code snippets for common functionality, examples, and guidelines.
Posts: 48
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
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
Ranorex Guru
Ranorex Guru
Posts: 7469
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


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
        		//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

Posts: 9
Joined: Tue Sep 10, 2019 1:30 pm

Re: How to check not visible element

Post by AdamG » Tue Feb 04, 2020 4:09 pm


So what is the purpose, and what is the usage of the Validate.NotExists method...?

Using that on an element that is not present results in the Element not found error, which defies the purpose...


Re: How to check not visible element

Post by Vega » Tue Feb 04, 2020 6:35 pm

It is to validate that an item does not exist. Just because you can not visually see an item does not mean it does not exist in memory. Applications set the visible state of items to false all the time yet the item still exists. It usually depends on how your AUT was developed. Not visible != Not exist. You can test the functionality of Validate.NotExist() with the below steps:
  • Open Notepad
  • Track notepad
  • Create a validate not exists action on notpad
  • Leave notepad open and run the test, it should fail (Element for item <REPONAME>.UntitledNotepad.Self' does exist. )
  • Close notepad and run the test, you should get a passing validation
If you would like to share a Ranorex snapshot as well as the path you are using, we could probably figure out your issue from that. Are you using code? If so, would you be able to provide a snippet? I would guess that you are initializing a variable which points to the element before the validate not exists step, but Ranorex will try to find the item when you initialize it.

Hope this helps