Jump to content

How to detect when a web page is finished loading


Cez
 Share

Recommended Posts

Link to comment
Share on other sites

the AU3 help file says _IELoadWait(). can get confused with some sites.

Here's a bit of code I use, it's not great, but it gets the job done....

Run ("C:\program files\internet explorer\iexplore.exe http://www.google.com/")

If WinWait ("Google - Windows Internet Explorer","",5) = 1 Then

For $a=1 to 10

Sleep (1000)

If ControlGetText("Google - Windows Internet Explorer","","[CLASS:msctls_statusbar32; INSTANCE:1]") = "Done" Then

Sleep(1000)

If ControlGetText("Google - Windows Internet Explorer","","[CLASS:msctls_statusbar32; INSTANCE:1]") = "Done" Then

$a=10

EndIf

EndIf

Next

;do stuff

EndIf

Edited by weirddave
Link to comment
Share on other sites

Just to explain, since I can't get decent formatting to work so it looks a mess!

1:- It loads IE with google

2:- waits for the IE window with google in the title, times out after 5 secs

3:- iIf the window loads up, go into a for loop and check for done up to 10 times with a 1 second delay each time to give a 10 second timeout

4:- if we see done, wait 1 second and check again in case the page has decided to start loading more stuff. This can lead to an 11 second timeout....

Link to comment
Share on other sites

Interesting!

So I'd end up with:

#include <IE.au3>

$oIE = _IECreate ("http://www.google.com/")

If WinWait ("Google - Windows Internet Explorer","",5) = 1 Then

For $a=1 to 10

Sleep (1000)

If _IEPropertyGet ($oIE, "statustext") = "Done" Then

Sleep(1000)

If _IEPropertyGet ($oIE, "statustext") = "Done" Then

$a=10

EndIf

EndIf

Next

;do stuff

EndIf

Looking at IE.au3, I could replace:

_IEPropertyGet($oIE, "statustext")

with:

$oIE.StatusText()

I've kept the WinWait command for the moment, I need to think about checking @Error after _IECreate.

I can't see an @Error result that tells me if IE actually loaded or not, General Error perhaps?

Link to comment
Share on other sites

  • 6 years later...

Neither of those examples are good.

The one with _IECreate would (maybe) work, but no one wants to create anything but to use already existing page.

The one with _IEPropertyGet is also useless, because not only new explorer does not say "Done" anymore but also when page says "Done" it does not mean its "Done".

For example, there could be PDF file to display, so it will be "Done" then start downloading and when download complete, it will do another "Done" so technically its impossible to say when its "DONE" for sure because what ever content/code page runs will/could trigger status bar to turn into "Done" multiple times. I've seen this allot.

 

There has to be a better way:

Only when you want to detect specific pages you can use InetGet (download the page and do binary to string)

Then read the string and search for (part of the code page ends with)

If that part of the code exist, then page is loaded. Otherwise :(

This wold only work if you specify pages to download and its not a real time thing. To make it real time, you'd have to download and convert binary to string multiple times. So many that server would probably ban you.

 

 

There has to be another way.

I my self looking for what ever that would help me identify element in the browser window and weather or not its ready and accepting input, so i can continue on barcode scanning

Edited by tonycst
Link to comment
Share on other sites

6 years old still no answer :blink:

 

I went into messing with _IECreate() fuction and came up with

#include <GUIConstantsEx.au3>
#include <IE.au3>
$URL = "www.google.com"
$Browser = _IECreate ($URL,1)
_IEPropertySet ($Browser,"addressbar",0)
_IEPropertySet ($Browser,"toolbar",0)
$Done = 0
While 1
    $Wait = _IELoadWait ($Browser)
    If $Wait = 1 and $Done = 0 Then
        MsgBox(0,'','loaded',1)
        Assign ("Done",1)
    EndIf
    ;How do i go about finding if page is changed or reloaded ?
WEnd

It works great (i would like to do it on already existing web browser) but i dont know how to detect it again if something changes.

Any clues ?

Thanks !

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...