Page 1 of 1

Conditional if-else loop is not working

Posted: Tue Feb 26, 2019 9:32 am
by samarthpukale
Hello All,
I am from Dassault systems pune.
I want to make my script dynamic so I am using conditional if else loop in user code.
My If(Condition 1) is working fine but in else if(Condition 2) loop is not working as it is still searched for condition 1 instead of condition1.
My Sample code is

if(myrepo.InsecureConnectionMozillaFirefox.Advanced_Button.)

{

myrepo.InsecureConnectionMozillaFirefox.Advanced_Button.Click();

Delay.Seconds(3);

myrepo.InsecureConnectionMozillaFirefox.AddException_Button.Click();

Delay.Seconds(3);

myrepo.AddSecurityException.ConfirmSecurityException.Click();

Delay.Seconds(3);

myrepo.WebDocument3DPassportTermsCondition.Accept_Radio_Button.Click();

Delay.Seconds(3);

myrepo.WebDocument3DPassportTermsCondition.Go_Button.Click();


}

else if (myrepo.WebDocument3DPassportTermsCondition.Go_Button.Visible)


{
myrepo.WebDocument3DPassportTermsCondition.Accept_Radio_Button.Click();

Delay.Seconds(3);

myrepo.WebDocument3DPassportTermsCondition.Go_Button.Click();
}
Please help me.

Re: Conditional if-else loop is not working

Posted: Tue Feb 26, 2019 12:23 pm
by odklizec
Hi,

I'm somewhat confused from your description. Please clarify below points...
At first, there is missing part of code in the first condition. I guess there should be .Visible at the end of first condition?
At next, if I understand you right, the first condition passes OK and then you expect the second condition to be evaluated and if Go_Button.Visible is true, content of second condition should be performed? In this case, you must not use "else if"! Just use "if" condition. In case of "else if", this condition is evaluated only if the first condition is not fulfilled! But maybe I understand your problem incorrectly? ;)

Re: Conditional if-else loop is not working

Posted: Tue Mar 05, 2019 6:22 am
by samarthpukale
Hello,

Yes i have missed .Visible at the end of the code.
My question was if the 1st condition is satisfied then the if condition will execute. But if the 1st condition was failed then it should check for 2nd condition i.e else if condition right? In my case ranorex is reading only the 1st condition and executing that loop but if the 1st condition fails it is looking for 1st condition.
Any ways i got the solution. I used If else with Info.Exists(). It worked.

Thanks for your fast reply.

Re: Conditional if-else loop is not working

Posted: Tue Mar 05, 2019 9:02 am
by odklizec
Hi,

If first condition fails, the code should go to "Else" section. You mentioned, that Exists helped, while Visible always performed first condition? So my guess is, that Visible was not working right, the element was partially visible or there was more than just one element found with Visible==true? Exists() is definitely best solution for validating if an element exists or not.