Jump to content
Sign in to follow this  

Error Handling using IE.au3

Recommended Posts

I have created some scripts using IE.au3 but i havent implemented any good error handling logic yet. In case of any errors IE.au3 prints the errors in the console. I believe those errors are printed to console using __IEErrorNotify function. I want to use these error messages and insert those into a text file or an excel. Any ideas? Basically if error messages are generated from IE.au3 after accessing its functions, then i want to write them to a file.

Share this post

Link to post
Share on other sites

I can take care of writing anything to a text file or an excel but please help me getting hold of these error messages generated from IE.au3.

Share this post

Link to post
Share on other sites


I think you want _IEErrorHandlerRegister.

#include <IE.au3>
_IEErrorHandlerRegister("_IEErrorHandler") ; register custom IE error handler
; lets see it in action
$oIE = _IECreate("http://example.com", 0, 0) ; create (hidden) IE object
ConsoleWrite("URL: " & $oIE.document.URL & @CRLF) ; print URL to console
ConsoleWrite("Nothing: " & $oIE.triggerErrorHere & @CRLF) ; trigger error by invoking non existing attribute
; custom IE error handler function
Func _IEErrorHandler()
    Local $sError = "!> IE COM Error" & @CRLF
    $sError &= "-> ErrorScriptline   = " & $oIEErrorHandler.scriptline & @CRLF
    $sError &= "-> ErrorNumberHex     = " & Hex($oIEErrorHandler.number, 8) & @CRLF
    $sError &= "-> ErrorNumber       = " & $oIEErrorHandler.number & @CRLF
    $sError &= "-> ErrorWinDescription = " & StringStripWS($oIEErrorHandler.WinDescription, 2) & @CRLF
    $sError &= "-> ErrorDescription = " & StringStripWS($oIEErrorHandler.description, 2) & @CRLF
    $sError &= "-> ErrorSource       = " & $oIEErrorHandler.Source & @CRLF
    $sError &= "-> ErrorHelpFile       = " & $oIEErrorHandler.HelpFile & @CRLF
    $sError &= "-> ErrorHelpContext = " & $oIEErrorHandler.HelpContext & @CRLF
    $sError &= "-> ErrorLastDllError   = " & $oIEErrorHandler.LastDllError & @CRLF
    ConsoleWriteError($sError & @CRLF) ; do what you want with the error message
EndFunc   ;==>_IEErrorHandler
Edited by Robjong

Share this post

Link to post
Share on other sites

Yu can use _IEErrorHandlerRegister() withou wriing your own error handler and it will put the messages into global variables for you. Please read the helpfile for _IEErrorHandlerRegister().


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

Thank You for the reply!

@Dale - How do i use these global variables? I read the help file but couldnt figure out how to use it. Can you please refer my sample script below and show me how to use it.

@RobJong - I tried using the custom error handler but i am not sure why it doesnt seem to work. I read the help file for _IEErrorHandlerRegister but couldnt get this working. Please see the sample code below. I have given a wrong name attribute value for password. I do get the default message from IE.au3 like below but the custom error handler ( _IEErrorHandler()) in the script below is not called and it doesnt show below error message. I need some way to control these messages so that i can write it to a log file.

Error Message --

"--> IE.au3 V2.4-0 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidObjectType

--> IE.au3 V2.4-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType"


My Sample Script

#include <IE.au3>

_IEErrorHandlerRegister("_IEErrorHandler") ; register custom IE error handler

$oIE = _IEAttach("Dev Con - Internet Explorer", "Title")

$oDomain = _IEGetObjByName($oIE, "domain")

_IEFormElementSetValue($oDomain, "UNTOPR")

$oPwd = _IEGetObjByName($oIE, "password111") ; purposefully inserted a wrong name attribute value. So this line will throw error in the console.

_IEFormElementSetValue($oPwd, "TEst")

Func _IEErrorHandler()

ConsoleWriteError("I am in error handler function" & @CRLF)

Local $sError = "!> IE COM Error" & @CRLF

$sError &= "-> ErrorScriptline = " & $oIEErrorHandler.scriptline & @CRLF

$sError &= "-> ErrorNumberHex = " & Hex($oIEErrorHandler.number, 8) & @CRLF

$sError &= "-> ErrorNumber = " & $oIEErrorHandler.number & @CRLF

$sError &= "-> ErrorWinDescription = " & StringStripWS($oIEErrorHandler.WinDescription, 2) & @CRLF

$sError &= "-> ErrorDescription = " & StringStripWS($oIEErrorHandler.description, 2) & @CRLF

$sError &= "-> ErrorSource = " & $oIEErrorHandler.Source & @CRLF

$sError &= "-> ErrorHelpFile = " & $oIEErrorHandler.HelpFile & @CRLF

$sError &= "-> ErrorHelpContext = " & $oIEErrorHandler.HelpContext & @CRLF

$sError &= "-> ErrorLastDllError = " & $oIEErrorHandler.LastDllError & @CRLF

ConsoleWriteError("Error Message --> " & $sError & @CRLF) ; do what you want with the error message

EndFunc ;==>_IEErrorHandler

THank you everybody for your time and help!

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  

  • Similar Content

    • By Colduction
      Hello again, i have a code that changes username to favorite, my problem is how to use ObjEvent() function to catch errors, i've red Help File and Forum's Topics but i can't understand too much😐

      Here is a code (I've copied this codes from a user of AutoIt Forum):
      $sOldUser = "Administrator" $sNewUser = "Admin" $oUser = ObjGet("WinNT://" & @ComputerName & "/" & $sOldUser & ",user") $oComputer = ObjGet("WinNT://" & @ComputerName) $oNewUser = $oComputer.MoveHere($oUser.ADsPath, $sNewUser) Thanks for your care, I'm new to AutoIt and days should be passed with my coding and practicing to don't bother you :)❤
    • By zuladabef
      I want to set the value of a input, but I only have the input name and input id.  I cannot find a form in the source.  Form collection does not return any results.  
      Is there a way to use FormElementSetValue without a form name? Can I use _IEGetObjByName or _IEGetObjById?  If so, how do I set the value once I have the object? Where do I go from here? Local $oIE = _IEAttach("[Website Goes Here"]) Local $oForm = _IEFormGetCollection($oIE, 1) Local $oQuery = _IEFormElementGetCollection($oForm, 4) _IEFormElementSetValue($oQuery, "Set it to this")  
    • By dpollard
      Hi Guys,
      I'm writing a script that loops through all the word documents in a given folder and inserts text into the footer.
      This is mostly working great.
      I have run into a problem where the footer in a few documents is somehow protected.
      If I open word manually I can select the text in the footer but I can't add to it.
      I can update the main text in the document so it isn't simply password protected.
      Rather than try and unprotect it I'm happy just to skip over it.
      I currently get an error on the line shown below $oRange.Inserafter
            ; Insert the text       $oRange.Insertafter($text1 & $LastSavedDay &'/'& $LastSavedMonth &'/'& $LastSavedYear & $text2)       If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Insert Modified Date", _         "Error 010 Setting first footer InsertAfter location" & $file & @CRLF & "@error = " & @error & ", @extended = " & @extended) "E:\FileConversion\InsertCreationDate2.au3" (120) : ==> The requested action with this object has failed.:
      $oRange.Insertafter($text1 & $LastSavedDay &'/'& $LastSavedMonth &'/'& $LastSavedYear & $text2)
      $oRange^ ERROR
      It stops at the above line and does not get to the @error statement.
      I guess what I really need is to catch this error and jump to the next document in my for next loop.
      I'm happy to add the entire script to this post if anyone thinks that will help.
      Any Ideas?
    • By Seminko
      Hey there,
      below function returns an "object collection" (not sure if that's the correct term) of 'a' elements grabbed from within //*[@id="J_DetailMeta"].
      However, I need the returned collection not to include objects with 'aria-disabled = true'. Is there a way of removing specific objects from such a collection?
      Func GetObjectList($sPicker) $oDetailMeta = _IEGetObjById($oIE, "J_DetailMeta") If Not @error Then $tags = $oDetailMeta.GetElementsByTagName("ul") For $tag in $tags $data_ID_value = $tag.GetAttribute("data-property") If $sPicker = "color" Then If $data_ID_value = '????' Or $data_ID_value = "????" Then $oReturnList = $tag.GetElementsByTagName("a") EndIf ElseIf $sPicker = "network" Then If $data_ID_value = '????' Then $oReturnList = $tag.GetElementsByTagName("a") EndIf ElseIf $sPicker = "storage" Then If $data_ID_value = '????' Then $oReturnList = $tag.GetElementsByTagName("a") EndIf EndIf Next EndIf Return $oReturnList EndFunc $oColorList = GetObjectList("color") For $oColor In $oColorList If StringInStr($oColor.GetAttribute("aria-disabled"), "true") <= 0 Then ; remove object from the collection ??? EndIf Next  
    • By careca
      Hi, i feel im close to getting it to work, but there must be something im missing that's probably easy for you experts.
      #include <IE.au3> #include <File.au3> #include <MsgBoxConstants.au3> $Visible = 1 Local $oIE $oIE = _IECreate("https://beemp3s.net/mp3-download.html", 0, $Visible, 1, 1) _IELoadWait($oIE) If $oIE <> @error Then ;_ArrayText() _QuerySite('Finding Hope - Without You') ;_IEQuit($oIE) ;Exit Else MsgBox(64 + 262144, 'Fail', 'Could not create a new window') EndIf ;============================================================================= Func _QuerySite($Name) Local $oIE_ObjectToSearch = _IEGetObjById($oIE, 'query') _IEDocInsertText($oIE_ObjectToSearch, $Name) Local $oIE_ObjectToClick = _IEGetObjById($oIE, "search-action") _IEAction($oIE_ObjectToClick, 'click') _IELoadWait($oIE, 2000) ;============================================================================= Local $oSubmitClick = _IEGetObjById($oIE, "col-md-12") _IEAction($oSubmitClick, "click") _IELoadWait($oIE, 2000) ;============================================================================= Local $oBtns = _IETagNameGetCollection($oIE, "div") For $oBtn In $oBtns If String($oBtn.classname) = "col-md-12" Then If String($oBtn.innertext) = "Download / Play" Then ConsoleWrite($oBtn.innertext & @CRLF) _IEAction($oBtn, 'click') EndIf EndIf Next ;============================================================================= ;Local $oElements = _IETagNameAllGetCollection($oIE) ;For $oElement In $oElements ; If $oElement.id Then MsgBox($MB_SYSTEMMODAL, "Element Info", "Tagname: " & $oElement.tagname & @CRLF & "id: " & $oElement.id & @CRLF & "innerText: " & $oElement.innerText) ;Next ;============================================================================= ;_IEQuit($oIE) ;Exit ;============================================================================= EndFunc ;==>_QuerySite ;============================================================================= Func _ArrayText() If FileExists('Titles.txt') Then Local $FO = FileOpen('Titles.txt') Local $R2A = FileReadToArray($FO) Local $iLineCount = @extended FileClose($FO) For $f = 0 To $iLineCount - 1 ConsoleWrite($f & ' - ' & $R2A[$f] & @CRLF) _QuerySite($R2A[$f]) Next Else MsgBox(64 + 262144, 'Fail', 'Could not find the file Titles.txt') EndIf EndFunc ;==>_ArrayText ;============================================================================= The idea is to get into this site, write into the search and click, which i did, but now the problem is clicking in any of the buttons in the results page, im looking for a way to click the first one, it always matches to what i want, so no need to fiddle around.
      Thanks for help in advance.

  • Create New...