Jump to content
Sign in to follow this  

[Func] _IELoadWaitComplete

Recommended Posts


Hey guys. Here is a function to wait a page to be loaded. Differences with _IeLoadWait is that it works with Javascript generated pages. You can use it even if there is lots of Javascript in the page.

Warnings : it dosn't work 100% Time and may returns before the page is really fully loaded, but itdoes better than the _IELoadWait function. If it don't work, you have to find another way to wait your page to be fully loaded, when there is a lot of AJAX for example.

Have fun


$oIE = _IECreate("http://google.fr")
Global $CountDownloads,$StatusTextChangeTime = _NowCalc()


; #FUNCTION# ====================================================================================================================
; Name...........: _IELoadWaitComplete
; Description ...: Wait for a browser page with javascript load to complete before return
; Parameters ....: $o_object - Object variable of an InternetExplorer.Application
; $i_level - Optional: Level of verification before return
; $i_delay - Optional: Milliseconds to wait before checking status
; $i_timeout - Optional: Period of time to wait before exiting function
; (default = 10000 ms aka 10 sec)
; Return values .: On Success - Returns the level loaded
; On Failure - Returns 0
; Author ........: Timothée Malossane
; Requires ......: IE.au3 and Date.au3
; Remarks .......: _IELoadWait function is called whatever $i_level is.
; There are 4 levels of verification :
; level 1 : Only Busy property is checked
; level 2 : Busy and readyState properties are checked
; level 3 : [DEFAULT]Busy, readyState and Download properties are checked. Each download started MUCH BE ended
; level 4 : Busy, readyState, Download and StatusText properties are checked. Each download started MUCH BE ended. The statusText must stay the same for 1 second to return ok
; Warning : On Level 4 : The function may not return instantly and wait until 1 second more.
; Dont forget to include those 2 lines in head of your script.
; Global $CountDownloads,$StatusTextChangeTime = _NowCalc()
; $SinkObject=ObjEvent($oIE,"_IELoadWaitComplete_","DWebBrowserEvents2")
; This function need _IELoadWaitComplete_DownloadBegin,_IELoadWaitComplete_DownloadComplete and _IELoadWaitComplete_StatusTextChange to work
; ===============================================================================================================================

Func _IELoadWaitComplete(ByRef $o_object ,$i_level = 3, $i_delay = 0 , $i_timeout = 10000)
Local $ok = 0
Local $t = TimerInit()
While ($ok < $i_level And TimerDiff($t)<$i_timeout)
If (Not $o_object.Busy()) Then
If(String($o_object.readyState) <> 1) Then
If $CountDownloads <=0 Then
If (_DateDiff('s',$StatusTextChangeTime,_NowCalc()) >= 1) Then
$ok = 4
$ok = 3
$ok = 2
$ok = 1
$ok = 0
return $ok

Func _IELoadWaitComplete_DownloadBegin($text)
$CountDownloads += 1

Func _IELoadWaitComplete_DownloadComplete($text)
$CountDownloads -= 1
Func _IELoadWaitComplete_StatusTextChange($text)
$StatusTextChangeTime = _NowCalc()
Edited by timmalos

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

Sign in to follow this  


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.