need valid exists condition logic for IF statement

Ask general questions here.
Posts: 8
Joined: Fri Nov 06, 2020 12:23 am

need valid exists condition logic for IF statement

Post by Dhundley » Tue Nov 24, 2020 11:17 pm

I'm using Ranorex 9.3

What I'm trying to accomplish is this:

the first time my script runs on a new day, after a particular OK button is pressed/clicked, it encounters a Yes button that gets pressed/clicked followed by several other actions. if the script runs again on the same day and the same OK button is clicked, the Yes button will not even materialize in the application. So, I converted all the "bunch of other stuff" (as indicated in the psuedo-code below) into a code module but I'm having a hard time figuring out how to create the if statement below. the validate.Exists action is a void method and I need some sort of action that will check for the button and return true if it exists and false if it doesn't without failing/stopping the script at this point. I also want to limit the duration for finding the Yesbutton to no more than 5 seconds. Any suggestions?

if (Yesbutton.exists)
<do a bunch of other stuff>

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

Re: need valid exists condition logic for IF statement

Post by odklizec » Wed Nov 25, 2020 7:23 am


I think this should be an easy task. Here is an example code, where elementToCheck is assigned repo element...

Code: Select all

    public void CheckIfExists(RepoItemInfo elementToCheck)  
        if (elementToCheck.Exists(5000)) //exists method with search timeout 5s
            //if exist, do something  
            //if does not exists, do something else  
BTW, I would recommend to use standard Click action or Move/Click sequence, instead of PerformClick, which may not trigger "mouse" events in called element! PerformClick simply sends "click" to element, but without invoking assigned mouse-related events! Therefore, your app may fail to do what it is designed for ;)
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