Jump to content

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.

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

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!

Link to post
Share on other sites
  • 5 years later...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By walec
      I have problem with Set Value for control slider on webside.
      Anyone have any idea for a solution?
      I tried but it doesn't work.
      Local $Strength = _IEGetObjById($oIE_Strona, "strength_value") Local $oText = _IEFormElementGetObjByName($Strength, "valuee") _IEFormElementSetValue($oText, "6") or
      _IENavigate ($oIE_Strona, "https://guantanamo.prisonwarsonline.com/gym/") Local $oDiv = $oIE_Strona.Document.GetElementByID("strength_value") Local $oAttribute = $oDiv.getAttribute("valuee") If IsObj ( $oAttribute ) Then $oAttribute.value = "6" EndIf Best Regards
    • By Mariog2000
      I've tried for a few days to simply open a url in IE and click an IE object that I can't "TAB" to and don't want to use a mouse-click if at all possible.  I've read up on things like using IEAction and IETagNameGetCollection to find the object but not smart enough to figure out how that works with my url or how to tell if my url is "basic" or a "form", "frameset", "iframe", etc.
      The other problem is I've tried using the "Run" and "ShellExecute" commands to open the browser, which works, but it opens it in a way that doesn't include my currently logged in user account.  For example, if I just click IE or Chrome for that matter and open my default homepage of google, the page that opens knows I'm logged in.  When I use "Send" "ShellExecute" or "_IE_Create" they always open pages generically which would require a login.
      So questions are, if I have a URL I'm trying to open, that's passes the currently logged on users credentials when opening the page (no clue where that happens)
      1.  Are there any code examples someone is willing to share that opens my IE maximized, with logged in credentials, and
      2.  Once that works, can someone suggest a technique a non-developer can find which IE Objects I need to send a "click" to so it opens the correct menu, pop-up, url, etc., associated with that object.  I've copied what doesn't work and sure I'm way off but it's not for a lack of effort. I'll keep trying and post updates but not looking good 🙂
      #include <IE.au3>
      Call ("selection")
      Func selection ()
      Global $oIE = _IECreate ("https://internal-webpage.aspx")
      Local $selectid = _IEGetObjByName ($oIE, "signageNo")
      Local $button = _IEGetObjByName ($oIE, "GO")

      _IEFormElementOptionSelect ($selectid, "3")
      _IEAction ($button,"click")
      #include <IE.au3> Call ("selection") Func selection () Global $oIE = _IECreate ("https://internal-webpage.aspx") Local $selectid = _IEGetObjByName ($oIE, "signageNo") Local $button = _IEGetObjByName ($oIE, "GO") _IEFormElementOptionSelect ($selectid, "3") _IEAction ($button,"click") EndFunc 1. 
    • 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?
  • Create New...