Skip to content

Commit afeb5fc

Browse files
committed
Add _WD_LoadWait
1 parent d980793 commit afeb5fc

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

wd_helper.au3

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,4 +554,67 @@ Func _WD_HighlightElements($sSession, $aElements, $iMethod = 1)
554554
$iHighlightedElements += (_WD_HighlightElement($sSession, $aElements[$i], $iMethod) = True ? 1 : 0)
555555
Next
556556
Return ($iHighlightedElements > 0 ? SetError(0, $iHighlightedElements, True) : SetError(1, 0, False))
557-
EndFunc ;==>_WD_HighlightElements
557+
EndFunc ;==>_WD_HighlightElements
558+
559+
560+
561+
; #FUNCTION# ====================================================================================================================
562+
; Name ..........: _WD_LoadWait
563+
; Description ...: Wait for a browser page load to complete before returning
564+
; Syntax ........: _WD_LoadWait($sSession[, $iDelay = 0[, $iTimeout = -1[, $sElement = '']]])
565+
; Parameters ....: $sSession - Session ID from _WDCreateSession
566+
; $iDelay - [optional] Milliseconds to wait before checking status
567+
; $iTimeout - [optional] Period of time to wait before exiting function
568+
; $sElement - [optional] Element ID to confirm DOM invalidation
569+
; Return values .: Success - 1
570+
; Failure - 0 and sets the @error flag to non-zero
571+
; Author ........: Dan Pollak
572+
; Modified ......:
573+
; Remarks .......:
574+
; Related .......:
575+
; Link ..........:
576+
; Example .......: No
577+
; ===============================================================================================================================
578+
Func _WD_LoadWait($sSession, $iDelay = 0, $iTimeout = -1, $sElement = '')
579+
Local Const $sFuncName = "_WD_LoadWait"
580+
Local $iErr, $sResponse, $sJSON, $sReadyState
581+
582+
If $iTimeout = -1 Then $iTimeout = $_WD_DefaultTimeout
583+
584+
If $iDelay Then Sleep($iDelay)
585+
586+
Local $hLoadWaitTimer = TimerInit()
587+
588+
While True
589+
If $sElement <> '' Then
590+
_WD_ElementAction($sSession, $sElement, 'name')
591+
592+
If $_WD_HTTPRESULT = $HTTP_STATUS_NOT_FOUND Then $sElement = ''
593+
Else
594+
$sResponse = _WD_ExecuteScript($sSession, 'return document.readyState', '')
595+
$iErr = @error
596+
597+
If $iErr Then
598+
ExitLoop
599+
EndIf
600+
601+
$sJSON = Json_Decode($sResponse)
602+
$sReadyState = Json_Get($sJSON, "[value]")
603+
604+
If $sReadyState = 'complete' Then ExitLoop
605+
EndIf
606+
607+
If (TimerDiff($hLoadWaitTimer) > $iTimeout) Then
608+
$iErr = $_WD_ERROR_Timeout
609+
ExitLoop
610+
EndIf
611+
612+
Sleep(100)
613+
WEnd
614+
615+
If $iErr Then
616+
Return SetError(__WD_Error($sFuncName, $iErr, ""), 0, 0)
617+
EndIf
618+
619+
Return SetError($_WD_ERROR_Success, 0, 1)
620+
EndFunc

0 commit comments

Comments
 (0)