I'm automating an IE page and need to wait for the page to load before populating a textbox. One problem is the way IIS names the DOM objects dynamically. I have to search the DOM looking for a certain string. When I find it, I know I have the right object. $oForm = _IEFormGetObjByName ($oIE, "form1")
$oElems = _IEFormElementGetCollection ($oForm)
For $oElem in $oElems
if StringInStr($oElem.id,"tblEditFilterstxtValue") > 0 Then
$oTbox = $oElem
EndIf
Next
_IEFormElementSetValue($oTbox, $sName) The way the page is designed, a modal popup appears, but if the popup has not loaded I get: _IEFormElementSetValue($oTbox, "") _IEFormElementSetValue(^ ERROR So I added _IEErrorHandlerRegister () to the top of my script. (But the custom error handler works sometimes and not others. Odd.) When it does work I get the following output: @@ Debug(704) : $ErrorOutput = --> COM Error Encountered in di.au3 ----> $ErrorScriptline = 2439 ----> $ErrorNumberHex = 80020009 ----> $ErrorNumber = -2147352567 ----> $ErrorWinDescription = ----> $ErrorDescription = Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus. ----> $ErrorSource = htmlfile ----> $ErrorHelpFile = C:\WINDOWS\system32\mshtml.hlp ----> $ErrorHelpContext = 0 ----> $ErrorLastDllError = 0 If I put a sleep() in the code, it will usually work, but depending on the connection it could fail. So with a fast internet connection (LAN) the sleep interval can be small, but across the web, it needs to be large. I end up with a sluggish app on the LAN in order to get the script to work over the web. So what I would like to do is put in a loop that checks for the object, but the script keeps crashing because the object is not visible/enabled or can't accept the focus. $iTimer = TimerInit() ; Timeout timer
While 1
$o_Form = _IEGetObjByID($oIE, $oTbox.id)
If Not @error And IsObj($o_Form) Then ExitLoop
If TimerDiff($iTimer) >= 30000 Then
MsgBox(16, "Error", "Timeout.")
Exit
EndIf
Sleep(100)
WEnd
_IEFormElementSetValue($oTbox, $sName) This crashes at _IEGetObjByID($oIE, $oTbox.id) because $oTbox is not accessable. So how do I test to see if this object is accessable without having to sleep() and making my app sluggish? The second issue is the funky behavior of _IEErrorHandlerRegister (). I did find some reference to this behavior in the forum, but not much.