Waiting for web page to complete loading

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Trevor Hughes
Junior Coder
Posts: 25
Joined: Sun Dec 15, 2013 9:27 pm

Waiting for web page to complete loading

Post by Trevor Hughes » Wed Mar 05, 2014 8:47 pm

Hello

I am undertaking testing using various web browsers, mainly Firefox. In order to have the scripts run successfully I have had to have a long WAIT time to cover occasions when the page takes longer to load.

Is there a way to use the image recognition features within Macro Scheduler to test if a page has loaded and if not loop until the page has loaded?

Any suggestions would be appreciated.

Kind regards
Trevor

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

Post by Marcus Tettmar » Thu Mar 06, 2014 7:22 am

Yes. Use WaitScreenImage and capture something that is only present when the page has fully loaded. That could be something that appears on the page itself, such as the thing you intend to interact with next, or a status bar message, or ... whatever visual cue works for you.

If using IE you don't need to do this as we have the IE functions which hook into IE and you can use IEWaitDocumentComplete.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

JohnOlek
Newbie
Posts: 5
Joined: Wed May 14, 2014 4:20 pm

Re: Waiting for web page to complete loading

Post by JohnOlek » Wed May 14, 2014 4:37 pm

The way I usually handle this is to look for a single pixel that changes when a page is loading and wait until it has changed back to its regular, non-loading color.

I am currently working on a script to automate a process in PeopleSoft. Sometimes PeopleSoft runs very quickly, and other times it can take a few seconds to load. It's very important that my script waits until that process finishes before continuing, and it happens a lot during this business process. I defined the following subroutine, that I call multiple times throughout the script:

END>waitPSoftReady
  View Snippet Page

16777215 is the pixel color at coordinates 1871,182 when PeopleSoft isn't busy. I like to define variables like psoftBusyX at the top of my script so they are easy to find/update if I need to transfer it to someone else's computer.

Does anyone have any thoughts on if this approach is better or worse than WaitScreenImage? Does WaitScreenImage work well if different screen resolutions are being used? If packaging a script into an .exe, how are assets like saved bitmaps included?

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

Re: Waiting for web page to complete loading

Post by Marcus Tettmar » Wed May 14, 2014 5:11 pm

WaitScreenImage with the CCOEFF matching algorithm is quite portable and should cope fine with different screen resolutions, but you'd need to test it out.

With v14 the image recognition wizard saves BMP files to BMP_DIR which is a folder placed at the same level as the script file with the same name as the script. The compiler will automatically copy this folder over to the .exe file location and as long as the folder is included with the .exe it should all work.

Obviously if you used fixed paths this won't work and you'll have to copy manually. Another way is to use SCRIPT_DIR and just keep the BMP files with the .exe in the same folder.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

JohnOlek
Newbie
Posts: 5
Joined: Wed May 14, 2014 4:20 pm

Re: Waiting for web page to complete loading

Post by JohnOlek » Wed May 14, 2014 5:58 pm

Thanks so much for the info!

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