Sign in to follow this  
Followers 0
Capel

IE Error handling

7 posts in this topic

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.

Share this post


Link to post
Share on other sites



1. Have a look at debugbar to ensure there is no client side processing.

2. You may want to add something like while (tag not loaded) sleep 100.

3. _IEErrorHandlerRegister () usually is good, Maybe it is not always encounting the issue.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Is "tag not loaded" a method of the DOM?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Is "tag not loaded" a method of the DOM?

No, what he's saying is don't move on until $oTbox is valid. You loop through the collection and ASSUME $oTbox was found and set correctly before going on. Instead, put that inside an outer loop that reacquires the collection and tries again until it is found:
$oForm = _IEFormGetObjByName($oIE, "form1")
If @error = 0 Then
    Do
        $oTbox = 0
        $oElems = _IEFormElementGetCollection($oForm)
        For $oElem In $oElems
            If StringInStr($oElem.id, "tblEditFilterstxtValue") > 0 Then
                $oTbox = $oElem
                ExitLoop
            EndIf
        Next
    Until IsObj($oTbox)
    _IEFormElementSetValue($oTbox, $sName)
Else
    MsgBox(16, "Error", "Failed to get 'form1'.")
EndIf

:(

P.S. Also, I just noticed that you were not breaking out of the loop when you DID find it, so $oTbox was getting overwritten. Fixed that by adding ExitLoop inside your For/Next loop.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks Psalty. I deleted the ExitLoop when I cleaned up the code to post in this thread, but good eye! Thanks again and I'll give this a shot.

Share this post


Link to post
Share on other sites

Psalty,

This did not work. The nature of the modal form is that the $oTbox is an object in the DOM all the time, it is just not visible/accessible all the time. So I still need some way to test if $oTbox is accessible without causing a COM error.

Share this post


Link to post
Share on other sites

You can examine the .style.display property of the element.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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  
Followers 0