Last active
October 9, 2017 04:49
AutoIt Snippet - _IEWaitForTagText
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; #FUNCTION# ==================================================================================================================== | |
; Name ..........: _IEWaitForTagText | |
; Description ...: Waits for a HTML tag to appear with the specified text | |
; Syntax ........: _IEWaitForTagText($oObject, $sTagName, $sTagText[, $iTimeout = 0[, $bNoError = True]]) | |
; Parameters ....: $oObject - Object related to IE (Any Window, Frame, IFrame or any DOM object). | |
; $sTagName - Name of the HTML tag (p, img, tr, etc). | |
; $sTagText - The (inner) text of the tag to wait for. | |
; $iTimeout - [optional] Timeout for the wait in milliseconds. Default is 0 (No timeout). | |
; $bNoError - [optional] Temporarily disable IE errors messages in the console. Default is True. | |
; Return values .: Success: The DOM element's object | |
; Failure: False and @error is set to 1 | |
; Author ........: Damon Harris (TheDcoder) | |
; Remarks .......: 1. Failure is impossible if $iTimeout is set to 0 | |
; 2. This is how $bNoError works: | |
; * If $bNoError is True, then _IEErrorNotify(False) is called and _IEErrorNotify(True) is called after the wait. | |
; * If $bNoError is True and _IEErrorNotify() is False, nothing will be changed. | |
; * If $bNoError is False, nothing will be changed. | |
; Related .......: _IELoadWait | |
; Link ..........: https://git.io/vHxOT | |
; Example .......: _IEWaitForTagText($oIE, "p", "logout") | |
; =============================================================================================================================== | |
Func _IEWaitForTagText($oObject, $sTagName, $sTagText, $iTimeout = 0, $bNoError = True) | |
Local $oTags, $hTimer, $sText, $bTurnOnNotify = False | |
If Not $iTimeout = 0 Then $hTimer = TimerInit() | |
If $bNoError And _IEErrorNotify() Then | |
_IEErrorNotify(False) | |
$bTurnOnNotify = True | |
EndIf | |
Do | |
$oTags = _IETagNameGetCollection($oObject, $sTagName) | |
For $oTag In $oTags | |
$sText = _IEPropertyGet($oTag, "innertext") | |
If @error Then ContinueLoop | |
If ($sText = $sTagText) Then | |
If $bTurnOnNotify Then _IEErrorNotify(True) | |
Return $oTag | |
EndIf | |
Sleep(10) | |
Next | |
Until ($iTimeout = 0) ? False : (TimerDiff($hTimer) >= $iTimeout) | |
If $bTurnOnNotify Then _IEErrorNotify(True) | |
Return SetError(1, 0, False) | |
EndFunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment