timmalos Posted July 12, 2012 Posted July 12, 2012 (edited) 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 funUsage:#include #include $oIE = _IECreate("http://google.fr") Global $CountDownloads,$StatusTextChangeTime = _NowCalc() $SinkObject=ObjEvent($oIE,"_IELoadWaitComplete_","DWebBrowserEvents2") _IELinkClickByIndex($oIE,0) _IELoadWaitComplete($oIE,4)Function:expandcollapse popup; #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() sleep($i_delay+100) _IELoadWait($o_object,0,$i_timeout) 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 Else $ok = 3 EndIf Else $ok = 2 EndIf Else $ok = 1 EndIf Else $ok = 0 EndIf sleep(100) WEnd return $ok EndFunc Func _IELoadWaitComplete_DownloadBegin($text) $CountDownloads += 1 EndFunc Func _IELoadWaitComplete_DownloadComplete($text) $CountDownloads -= 1 EndFunc Func _IELoadWaitComplete_StatusTextChange($text) $StatusTextChangeTime = _NowCalc() EndFunc Edited July 12, 2012 by timmalos
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now