Conditional if-else loop is not working

Ask general questions here.
samarthpukale
Posts: 8
Joined: Tue Feb 19, 2019 7:44 am

Conditional if-else loop is not working

Post by samarthpukale » Tue Feb 26, 2019 9:32 am

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.

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

Re: Conditional if-else loop is not working

Post by odklizec » Tue Feb 26, 2019 12:23 pm

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? ;)
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

samarthpukale
Posts: 8
Joined: Tue Feb 19, 2019 7:44 am

Re: Conditional if-else loop is not working

Post by samarthpukale » Tue Mar 05, 2019 6:22 am

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.

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

Re: Conditional if-else loop is not working

Post by odklizec » Tue Mar 05, 2019 9:02 am

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