What to do when a browser doesnt load?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Joe
Newbie
Posts: 4
Joined: Fri Jul 10, 2009 3:09 pm

What to do when a browser doesnt load?

Post by Joe » Fri Jul 10, 2009 6:23 pm

I have an issue with a file I download from a website. I have a script that executes in the morning before anyone enters the office. Sometimes this script executes perfectly, and sometimes it fails miserably. The only reason I can figure out that it would fail would be because the website that I am calling to load doesnt load up, and subsequently, the script fails to enter the username/password, then log in, click links and download the file. How would I go about making sure the window has loaded, and if it doesnt load, start the script over from the beginning, and try to load the page again? I would like it to continue to do this until the page actually loaded and then move on to the rest of the script. Any suggestions on how to make this work?

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Jul 10, 2009 6:58 pm

A number of ways - all depend on what method you are using of controlling the web page. If you're using WebRecorder you'll have the IEWait function which will wait for the page to load. Then when it's loaded you could use the ContainsText function to see if contains text that appears on the successful page. Choose some text that only appears on that page, or choose text that appears on an error page - you get the idea.

And/Or you could use the text capture function to see if text appears in the browser window - same idea - look for text that only appears on the correct page, so if you don't get that text the page hasn't loaded, and some other page exists instead - such as an error page. Or do it the other way round and look for the existence of error text.

Or use FindImagePos - same idea but look for something graphical.

I'm sure there are other methods.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Synchronization with smart waits.

Post by gdyvig » Fri Jul 10, 2009 7:05 pm

Hi Joe,

You need to add some synchronization to your script with some smart waits. You want the script to wait long enough for the browser window to display but you don't want to keep waiting needlessly after the window has displayed.

In this example I am assuming the window title changes when you have succesfully reached the website.

Code: Select all

//Wait 5 minutes in case there is a problem at the web site
Let>WW_TIMEOUT=300
//Wait only for visible windows
Let>WF_TYPE=2
WaitWindowOpen>%websitename%*
//script will now wait 0-300 seconds until window open
//Did window ever open
if>WW_RESULT=FALSE
   MDL>window did not open after 5 heroic attempts!
   exit>
endif

SetFocus>>%websitename%*
Of couse you need to decide what is a reasonable length of time to wait for one attempt. What if the website never loads?

If the website does not load on the first attempt, use a Repeat loop to try again and again for a reasonable number of attempts.


Something like this


Code: Select all

SRT>LoadPage
  //Wait 5 minutes in case there is a problem at the web site
  Let>WW_TIMEOUT=300
  //Wait only for visible windows
  Let>WF_TYPE=2
  WaitWindowOpen>%websitename%*
  //script will now wait 0-300 seconds until window open
END>

Let>nCounter=0
Repeat>nCounter
 GoSub>LoadPage
 if>WW_RESULT=TRUE
     Let>nCounter=5
 else>
     Let>nCounter=%nCounter%+1
 endif
Until>nCounter=5

//Did window ever open
if>WW_RESULT=FALSE
   MDL>window did not open after 5 heroic attempts!
   exit>
endif

SetFocus>>%websitename%*


//continue with script
Use a similar technique with other smart waits depending on whether you are waiting for text, an image, or whatever. For example, use WaitScreenImage if you are waiting for a graphic to display.

This code has not been tested, so use at your own risk!


Gale

Joe
Newbie
Posts: 4
Joined: Fri Jul 10, 2009 3:09 pm

Post by Joe » Mon Jul 13, 2009 3:38 pm

Thanks for all the tips, i will try them out and report back if i am successful or not!!

Joe

Joe
Newbie
Posts: 4
Joined: Fri Jul 10, 2009 3:09 pm

Post by Joe » Thu Jul 30, 2009 11:22 pm

Just wanted to write back and say THANK YOU once again! So far it is working like a charm. I've not had the script fail on me once yet, so i sabotaged it just to make sure if the site didnt load it would write to a log file for me, and close out. Worked perfectly!!! I think I am going to change it to where it emails me instead of writing to a log file, but other than that, everything is great.

Thank you again!!!!

Joe

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts