Internet Explorer and WaitForScreenChange

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Internet Explorer and WaitForScreenChange

Post by PaulSR » Thu Apr 03, 2014 11:14 am

Hi All,

I've got a macro which queries a website for data then grabs some values. For the most part I used the web recorder to get what I needed and all those sections of code run great but I had one section where I had to revert to using image recognition.

The portion in question is where a list of customers can be displayed and I needed it to click the top one - as I couldn't achieve that via the web recorder (the name is different every time) I used findimagepos to identify the heading above the list and then offset the mousemove> to click on the first customer.

At this point I use a waitscreenimage> to hold up code execution until the webpage is loaded but I've noticed through experimentation that the combination of IE trying to load the page and the waitscreenimage command causes the page to take an absolute age to load. If I replace the waitscreenimage with a simple wait - say for 5 seconds - then the page will load really quickly but with the waitscreenimage it can be anywhere between 40seconds to 1 minute which is too long.

Does anybody have any idea why that would happen and a solution that might be better? The obvious problem is that if the page hasn't loaded within the 5 seconds wait it falls into the waitscreenimage cycle and it could subsequently be hung waiting to load for a long time.

Thanks in advance,

Paul.

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 Apr 03, 2014 1:40 pm

Odd. I don't really understand why this could happen. WaitScreenImage is just scanning the screen. Obviously it does have some effect on processor use because it has to routinely grab a screenshot of the screen. It's effectively a loop in which it keeps taking a screen snapshot and scanning it for the needle image you are waiting for. So while I can accept there may be a performance hit, I don't really see why it would affect IE in the way you are seeing. It doesn't do *anything* to IE as it is not process/app specific, it's simply scanning the visible screen area. But perhaps it is just slowing your PC up sufficiently that IE gets held up. That seems surprising to me. What's your PC spec?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Post by PaulSR » Thu Apr 03, 2014 2:02 pm

Hi Marcus,

This was out on the floor of the centre at an agents machine - I had seen this in the past so I had the Wait>2 before the WaitScreenImage and that seemed to resolve the problem (for me) but this seemingly is down to whether that is sufficient time for some or all of the page to load. I seem to get a better network speed than the centre agents so I think it's been ok for me (the macro is located on a network drive so that all those who need it have access).

I was thinking that upping the wait to 5 might be an idea but it obviously isn't directly addressing the problem.

I found some threads from a long time back but wasn't sure if they were still relevant - for example the "WaitReady" command which i've never used and some VBA subs :

http://www.mjtnet.com/forum/viewtopic.p ... lorer+busy

It's a strange one but I'm certain it's a combination of the webpage starting loading and the waitscreenimage...

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Apr 03, 2014 2:06 pm

I can't explain why this might be happening but as a stopgap sollution you might try something like this. Set WSI_TIMEOUT to 1 so that WaitScreenImage> times out after one second if the image was not found. If the image was not found wait for a second (or maybe 2). Then return to waiting for the image again. If the over head of WaitScreenImage> is slowing IE, the short waits might help.

Code: Select all

Let>WSI_TIMEOUT=1

Label>WaitingForImage
  WaitScreenImage>C:\file.bmp
  If>WSI_TIMEDOUT=TRUE
    Wait>1
    Goto>WaitingForImage
  EndIf

Let>WSI_TIMEOUT=0

PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Post by PaulSR » Fri Apr 04, 2014 11:00 am

Thanks JRL I will give that a shot and let you know how I get on.

PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Post by PaulSR » Tue Apr 08, 2014 9:01 am

JRL,

Thanks very much for your loop suggestion it appears to have done the trick and the macro executes a lot quicker now.

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