If - Else structures

Ask general questions here.
Nicolas.R
Posts: 3
Joined: Fri Apr 05, 2013 1:41 pm

If - Else structures

Post by Nicolas.R » Fri May 24, 2013 2:18 pm

Okay, I'm writing some automation cases for a couple of websites here at work that don't always behave the same way. A couple of sites can show you a popup asking you to log in or can just as well show you the main page with the sign in button in the upper corner or a sign in form can have an extra field depending on which proxy server I'm using at the moment.

To deal with that I've been trying to use IFs like "if fieldX exists then do this, else do this other thing" but the program always stops working whenever the first if turns out to be false.

Here is a code snippet:

Code: Select all

		public void signIn(String username, String password) {
		     Program.waitUntilLoaded(dom);
        	repo.signInPage.User.PressKeys(username);
        	repo.signInPage.Passwd.PressKeys(password);
       	
        	if (repo.signInPage.NucaptchaAnswerInfo.Exists()) {
        		repo.signInPage.NucaptchaAnswer.PressKeys("answer");
        	}
        	
        	repo.signInPage.SignIn.Click();        	
        }

If repo.signInPage.NucaptchaAnswerInfo.Exists() returns TRUE then it works perfectly but if it should return FALSE the program would just hang in there waiting eternally. I tried changing the timeout on the object in the repository to see if it was waiting to see if it eventually showed up before returning a FALSE but no luck.

I know it's probably something very easy but I can't figure out what I'm doing wrong.

Thanks.

mdgairaud
Posts: 87
Joined: Sun Aug 05, 2012 11:59 am
Location: Bilbao, Spain

Re: If - Else structures

Post by mdgairaud » Mon May 27, 2013 9:42 am

HI,

Have you try to put a delay after the If statement? I have some delays in my test because it executes extremely fast and Ranorex get lost with complex pages.

Try a 2sec delay

Code: Select all

Ranorex.Delay.Duration(2000);


regards,
Mateo.

Nicolas.R
Posts: 3
Joined: Fri Apr 05, 2013 1:41 pm

Re: If - Else structures

Post by Nicolas.R » Mon May 27, 2013 2:21 pm

That... seems to have made the trick. Thanks! I would have never even have considered that as a possible solution.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: If - Else structures

Post by Support Team » Mon May 27, 2013 3:12 pm

Hi,

Thanks Mateo for your suggestion!
In some situations it could happen that the control is not yet ready to be used even when it already exists.

Regards,
Markus
.
Image

mdgairaud
Posts: 87
Joined: Sun Aug 05, 2012 11:59 am
Location: Bilbao, Spain

Re: If - Else structures

Post by mdgairaud » Tue May 28, 2013 4:23 pm

nice! :D