Jump to content
Cez

How to detect when a web page is finished loading

Recommended Posts

BrettF
BrettF

Share this post


Link to post
Share on other sites
weirddave

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

Share this post


Link to post
Share on other sites
weirddave

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....

Share this post


Link to post
Share on other sites
techbard

Use $sVar = _IEPropertyGet($oIE, "statustext") for better work? :)

Share this post


Link to post
Share on other sites
weirddave

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?

Share this post


Link to post
Share on other sites
tonycst

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

Share this post


Link to post
Share on other sites
tonycst

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 !

Share this post


Link to post
Share on other sites
AlienStar

can I detect if the page is loaded in firefox instead of internet explorer ???

Share this post


Link to post
Share on other sites

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.