Skystrike

Managing Error handling with IE.au3 when using _IEAttach

6 posts in this topic

Hello everyone, this is my first post here. I'm a relative novice in autoit and have only picked it up in the past month. Currently i'm working on a project at work to automate the downloading of a bank statement from the bank's website. The main problem that I'm having is doing error handling when an error happened because the website crashed / timeout. I'm trying to capture the error event when one of my _IE functions failed to load because the page is frozen.

Here is a snippet of my code:

Func Test()
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

    $WinHandle = WinGetHandle("Test Website")
    $oIE = _IEAttach($WinHandle, "hwnd")

    $oFrame = _IEFrameGetObjByName($oIE, "leftFrame")
    $oDiv = _IEGetObjById($oFrame, "divFoldCont")
    $oDiv2 = _IEGetObjById($oDiv, "divFold0")
    $oDiv3 = _IEGetObjById($oDiv2,"divFoldSub0_1")
    $oLinks = _IELinkClickByText($oDiv3, "Bank Statement")
    Sleep(1000)
    
    ; Enter the Account Number
    $oFrame = _IEFrameGetObjByName($oIE, "workspace")
    $oLinks = _IELinkGetCollection($oFrame)

    For $oLink in $oLinks
        ;ConsoleWrite($oLink.href)
        _IEAction($oLink, "click")
        sleep(1000)
        ExitLoop
    Next
EndFunc

Func _ErrFunc($oError)

        $ErrorMessage = (@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)

EndFunc   ;==>_ErrFunc

I was planning for the program to send me an automated email to let me know that the program had crashed. This email will be triggered when an error event is captured. However here lies the problem. My script will always capture the following error message even when everything is working. The error message occur during _IEAttach.

--> IE.au3 T3.0-2 Warning from function _IEAttach, Cannot register internal error handler, cannot trap COM errors (Use _IEErrorHandlerRegister() to register a user error handler)

How do I modify my script so that this particular error won't trigger my error function?

P.S I'm open to suggestions on any advice to improve on my script.

P.S.S I can't use _IECreate because the website require me to login using a physical OTP, so I have to login to the website first before running the script.

Thanks for any guidance

Share this post


Link to post
Share on other sites



Try changing:

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

to:

_IEErrorHandlerRegister("_ErrFunc")

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Please read here:

   ie.au3 UDF with AutoIt v3.3.14.x  

btw.

Welcome to the forum

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Hello everyone, this is my first post here. I'm a relative novice in autoit and have only picked it up in the past month. Currently i'm working on a project at work to automate the downloading of a bank statement from the bank's website. The main problem that I'm having is doing error handling when an error happened because the website crashed / timeout. I'm trying to capture the error event when one of my _IE functions failed to load because the page is frozen.

Whats mean "frozen" is that entire iexploerer.exe not responding, or only this particular website is frozen and IE is still operative  ?


Func Test()
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

When you declare any variable in local scope then it is visible inside any other function even in _IE.... functions.

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Try changing:

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

to:

_IEErrorHandlerRegister("_ErrFunc")

 

Let me try this out. Does this mean that all of the error in the script will be handled by _IEErrorHandlerRegister ? What is the difference between this and the previous method that i tried?

Whats mean "frozen" is that entire iexploerer.exe not responding, or only this particular website is frozen and IE is still operative  ?

 


Func Test()
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

When you declare any variable in local scope then it is visible inside any other function even in _IE.... functions.

 

The website is frozen (Most likely it timed out). I will read through the post that you linked above and try it again.

 

Thanks all for the warm welcome

Share this post


Link to post
Share on other sites

Well changing the error handler to _IEErrorHandlerRegister worked it's magic. Thanks all for the support.

_IEErrorHandlerRegister("_ErrFunc")

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