Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ Microsoft Internet Explorer _ Waiting For A Web Page To Complete Loading

Posted by: dflak Jun 13 2013, 08:54 AM

I have tried

While ie.busy

While ie.readystate <> 4
  DoEvents  'wait until IE is done loading page.

  Loop Until ie.ReadyState = 4

None of which seem to work. Does anyone have a suggestion on how to get feedback from IE as to when it's done loading a page? Is there some incantation I haven't found yet?
This code does seem to work on our previous version of the dashboard which is mostly HTML. The version of the dashboard that fails is mostly javascript. I don't know if that makes a difference.
The only way I can get my code to work is with a fixed time interval. In other words, I add a 5 second delay between link clicks whether I need it or not and hope that it's enough: very wasteful and inprecise. Most of the times it works, some times it doesn't.

Posted by: ipisors Jun 13 2013, 09:15 AM

FWIW, here is what my experience with this problem has been. If you use that code and it doesn't appear to work, then here is what's actually happening. Internet explorer actually IS done loading the page. However, the page source code may well have called other [javascript, for example] functions which aren't done doing what they're going to do yet.
had this exact problem about a year ago when I was trying to manipulate a government webpage that the client used to submit and query information. The thing about manipulating IE is that (I know it's taboo to say things like this but I firmly believe this don't come down on me too hard), to some extent it's a lost cause. Sure IE is exposed to VBA, but the reality of it is that it's really not analogous to Excel, Outlook, Powerpoint etc., where you're creating a brand new program....with IE you have to worry about the programming of the guy who created the webpage. And unfortunately you will end up dealing with hidden functions, buttons with ID #'s that appear in the source code but don't appear to be readable by VBA, etc. To the extent that simple webpages can be manipulated by VBA I accept that in my day to day work but the rest of it I've somewhat skipped over because I realized that it was too 'hit and miss' to be worth much.
Long story short. When you use that code , the best it can do is see if IE is done loading the webpage. But there could be 16 other Javascript functions that got called ... they could take 1 minute more, 3 minutes more, or 10 minutes more to finish doing what they're doing. VBA wouldn't have a clue.
(ps I also noticed this when I once had to actually use VBA to CALL one of those functions, as opposed to clicking a button. This is when I realized this because I'd call the function, then use readystate type of was always wrong, and I was like WTH ?...until I realized IE is done loading, but there could be 3 other programming languages still doing their thing.....
Owouldn't feel bad about the hard coded delay, it's about what I would do too. However I've written a function that I use to display a nice "Processing, please wait.." to user. It makes all things better, as users are quite forgiving and some profressionalism is achieved if at least, the display appears intelligent.

Posted by: dflak Jun 13 2013, 09:19 AM

Well, the explanation is certainly reasonable, and I do believe that is exactly what is happening in this case. The good news is that the developers of this dashboard are on contract to our company. The bad news is that they probably haven't got a clue about VBA and a means of detecting when a page has "rendered." Nonetheless, I will reach out to them to see if they can help.

Posted by: ipisors Jun 13 2013, 09:21 AM

oh that's really good, yeah. Maybe they can do something to make it more like IE is truly hosed up until such time as....
which your code can then detect.
just noticed now your comment in OP about javascript hadn't even read that far originally sorry. Yes agreed.

Posted by: ipisors Jun 13 2013, 09:22 AM

Or maybe they could do something creative but really having their java functions create a little cookie/text file when it's done.
When you could loop until Dir()<>"" ........

Posted by: dflak Jun 13 2013, 10:50 AM

As I was told when I was flying, "Never fly yourself into a corner. Always give yourself a way out."
On theory, I have access to all the data I need to generate these reports in an Excel soluiton. I do need help from people to point me to where it is kept.
Also a coworker has access to a piece of testing software that looks like it could do the web crawling for us.
If neither of these solutions work, I will just hard code the seconds in there. This still beats the alternative: doing it by hand. But you know us engineers, not only does it have to work, but it has to look good while it's doing it. (Zen Engineering 101).