Page 1 of 1

need valid exists condition logic for IF statement

Posted: Tue Nov 24, 2020 11:17 pm
by Dhundley
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?

OKbutton.PerformClick();
if (Yesbutton.exists)
{
Yesbutton.PerformClick();
<do a bunch of other stuff>
}

Re: need valid exists condition logic for IF statement

Posted: Wed Nov 25, 2020 7:23 am
by odklizec
Hi,

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  
        }  
        else  
        {  
            //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 ;)