Jump to content
RamaKrishna9

Auto IT Error (IE.au3)

Recommended Posts

RamaKrishna9
Posted (edited)

Hi,

I've a requirement to login to multiple sites in a single click. So I implemented this functionality using IE.au3 UDF. But when I distributed this to other by converting the script to an executable (32-Bit version), they reported me the following error.

"Line: 3033 The requested action with this object has failed". Here the line number is not always the same (It is sometimes like 1671, 1678, etc,.). I'm struggling to overcome this error for the past 3 days without success. 

I'm a newbie to Auto IT and unable to figure out the problem. Can any one please help me out to resolve this error.?

 

Below are the details that depict the problem in detail:

Auto IT Version: 3.3.14.2

Code:

#include <IE.au3>
#include <MsgBoxConstants.au3>
AutoItSetOption ('TrayIconDebug', 1)
Const $navOpenInNewTab = 0x0800
Const $waitForPageLoad = 1
Const $timeToWaitForPageLoad = 20000
Global $HWND

Local $aUrls[] = ["https://www.codeproject.com/script/Membership/LogOn.aspx", "https://stackoverflow.com/users/login", "https://m.facebook.com"]
Local $aUserNames[] = ["username", "username", "username"]
Local $aPwds[] = ["password", "password", "password"]

Local $a_oIE[UBound($aUrls)]
Local $sPatternToMatchDomainName = "^(?i)(?:(?:[a-z]+):\/\/)?" & _ ; Protocol
                  "(?:(?:(?:[^@:]+))" & _         ; Username
                  "(?::(?:[^@]+))?@)?" & _        ; Password
                  "([^\/:]+)" & _                 ; Host
                  "(?::(?:\d+))?" & _             ; Port
                  "(?:\/(?:[^?]+)?)?" & _         ; Path
                  "(?:\?\N+)?"                    ; Query

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

For $i = 0 To UBound($aUrls)-1
    If $i = 0 Then
        $a_oIE[$i] = _IECreate($aUrls[$i], 0, 1, $waitForPageLoad)
        $HWND = _IEPropertyGet($a_oIE[$i], "hwnd")
        WinSetState($HWND, "", @SW_MAXIMIZE)
    Else
        $a_oIE[0].Navigate2($aUrls[$i], $navOpenInNewTab)
        Local $startTime = TimerInit()
        Local $aDomainName = StringRegExp($aUrls[$i], $sPatternToMatchDomainName, 1)
        While 1
            $a_oIE[$i] = _IEAttach($aDomainName[0], "url")
            If (IsObj($a_oIE[$i]) Or TimerDiff($startTime) >= $timeToWaitForPageLoad) Then ExitLoop
        WEND
    EndIf
    Local $bIterate = True
    If IsObj($a_oIE[$i]) Then
        Local $bContinueOuterLoop = False
        Local $startTime = TimerInit()
        While ($bIterate And TimerDiff($startTime) <= $timeToWaitForPageLoad)
;~          _IELoadWait($a_oIE[$i])
            Local $bButtonClicked = False
            Local $oInputs = _IETagNameGetCollection($a_oIE[$i], "input")
            If @error Then
                $bContinueOuterLoop = True
                ExitLoop
            EndIf
            For $oInput In $oInputs
                Sleep(500)
                If $oInput.type = "text" Then
                    $oInput.value = $aUserNames[$i]
                ElseIf $oInput.type = "email" Then
                    $oInput.value = $aUserNames[$i]
                ElseIf $oInput.type = "password" Then
                    $oInput.value = $aPwds[$i]
                    $bIterate = False
                EndIf
            Next
            For $oInput In $oInputs
                Sleep(500)
                If $oInput.type = "submit" Or $oInput.type = "button" Then
                    If StringInStr($oInput.value,"Login") Or StringInStr($oInput.value,"Log in") Or StringInStr($oInput.value,"Sign in") _
                        Or StringInStr($oInput.value,"Signin") Or StringInStr($oInput.value,"Submit") Or StringInStr($oInput.value,"Ok") _
                        Or StringInStr($oInput.value,"Click") Or StringInStr($oInput.value,"Go") Or StringInStr($oInput.value,"Continue") _
                        Or StringInStr($oInput.value,"Proceed") Or StringInStr($oInput.value,"Next") Or StringInStr($oInput.value,"Enter") Then
                        _IEAction($oInput, "click")
                        $bButtonClicked = True
                    EndIf
                    If $bButtonClicked Then
                        ExitLoop
                    EndIf
                ElseIf $oInput.type = "image" Then
                    If StringInStr($oInput.src,"Login") Or StringInStr($oInput.src,"Signin") Or StringInStr($oInput.src,"Submit") _
                        Or StringInStr($oInput.src,"Ok") Or StringInStr($oInput.src,"Click") Or StringInStr($oInput.src,"Go") Or StringInStr($oInput.src,"Continue") _
                        Or StringInStr($oInput.src,"Proceed") Then
                        _IEAction($oInput, "click")
                        $bButtonClicked = True
                    EndIf
                    If $bButtonClicked Then
                        ExitLoop
                    EndIf
                EndIf
            Next
            If Not $bButtonClicked Then
            Local $oButtons = _IETagNameGetCollection($a_oIE[$i], "button")
            If @error Then
                $bContinueOuterLoop = True
                ExitLoop
            EndIf
            For $oButton In $oButtons
                Sleep(500)
                If StringInStr($oButton.innerText,"Login") Or StringInStr($oButton.innerText,"Log in") Or StringInStr($oButton.innerText,"Sign in") _
                    Or StringInStr($oButton.innerText,"Signin") Or StringInStr($oButton.innerText,"Submit") Or StringInStr($oButton.innerText,"Ok") _
                    Or StringInStr($oButton.innerText,"Click") Or StringInStr($oButton.innerText,"Go") Or StringInStr($oButton.innerText,"Continue") _
                    Or StringInStr($oButton.innerText,"Proceed") Or StringInStr($oButton.innerText,"Next") Or StringInStr($oButton.innerText,"Enter") Then
                    _IEAction($oButton, "click")
                    $bButtonClicked = True
                EndIf
                If $bButtonClicked Then
                    ExitLoop
                EndIf
            Next
            EndIf
            If Not $bButtonClicked Then
            Local $oAncs = _IETagNameGetCollection($a_oIE[$i], "a")
            If @error Then
                $bContinueOuterLoop = True
                ExitLoop
            EndIf
            For $oAnc In $oAncs
                Sleep(500)
                If StringInStr($oAnc.href, "Go") Or StringInStr($oAnc.href, "Login") Or StringInStr($oAnc.href, "Signin") _
                    Or StringInStr($oAnc.href, "Submit") Or StringInStr($oAnc.innerText,"Signin") Or StringInStr($oAnc.innerText,"Sign in") _
                    Or StringInStr($oAnc.innerText,"Login") Or StringInStr($oAnc.innerText,"Log in") Or StringInStr($oAnc.innerText,"Submit") _
                    Or StringInStr($oAnc.innerText,"Enter") Then
                    _IEAction($oAnc, "click")
                    $bButtonClicked = True
                EndIf
                If $bButtonClicked Then
                    ExitLoop
                EndIf
            Next
            EndIf
            If Not $bButtonClicked Then
            Local $oImgs = _IETagNameGetCollection($a_oIE[$i], "img")
            If @error Then
                $bContinueOuterLoop = True
                ExitLoop
            EndIf
            For $oImg In $oImgs
                Sleep(500)
                If StringInStr($oImg.name, "Go") Or StringInStr($oImg.name, "Login") Or StringInStr($oImg.name, "Signin") _
                    Or StringInStr($oImg.name, "Submit") Or StringInStr($oImg.name,"Signin") Or StringInStr($oImg.src,"Sign in") _
                    Or StringInStr($oImg.src,"Login") Or StringInStr($oImg.src,"Log in") Or StringInStr($oImg.src,"Submit") Then
                    _IEAction($oAnc, "click")
                    $bButtonClicked = True
                EndIf
                If $bButtonClicked Then
                    ExitLoop
                EndIf
            Next
            EndIf
        WEND
        If $bContinueOuterLoop Then
            ContinueLoop
        EndIf
    EndIf
Next

Func _ErrFunc($oError)
    MsgBox($MB_ICONERROR, "Error!", @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

 

Edited by RamaKrishna9
Implemented 'COM Error' Handler

Share this post


Link to post
Share on other sites
JLogan3o13

First, moved to the appropriate forum, as the DEV forum very clearly states:

Quote

Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums

Second, when posting code, please put it into a code box. This gives us a nice scrolling box that is a whole lot easier to read (I have done it for you above).


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
RamaKrishna9
2 hours ago, JLogan3o13 said:

First, moved to the appropriate forum, as the DEV forum very clearly states:

Second, when posting code, please put it into a code box. This gives us a nice scrolling box that is a whole lot easier to read (I have done it for you above).

Sure. Will move this question to "AutoIt General Help and Support". I don't know where to post a question as this is my first question in the forum.

Share this post


Link to post
Share on other sites
JLogan3o13

@RamaKrishna9 At the top of each forum is a simple header to help you see what goes where.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
RamaKrishna9
2 hours ago, Danp2 said:

You should add a COM error handler. See Ex 1 in the help file entry for ObjEvent.

At some place in the forum I found "COM errors are no longer being fatal". I didn't understood the exact meaning of it. That is the reason not implemented any error handling (In other words don't know how to do this :()

Share this post


Link to post
Share on other sites
RamaKrishna9
On 5/25/2018 at 9:22 PM, Danp2 said:

Please do this.

Implemented this in the code. But when compiled, it is showing '-1' as scriptline number.

Share this post


Link to post
Share on other sites
Danp2

I believe that is the expected behavior for compiled code. Did the COM error handler return any other useful info?

You could add some additional logging to help isolate the commands that are failing.

Share this post


Link to post
Share on other sites
RamaKrishna9

Do IE.au3 have any dependencies with the IE Version, Windows Version, 32/64 Bit OS, etc,.?

Because the same logic is working in some machines and not working on other.

Share this post


Link to post
Share on other sites
mLipok
20 hours ago, RamaKrishna9 said:

Implemented this in the code. But when compiled, it is showing '-1' as scriptline number.

Did you read this:

And implement it in a proper way ?

 


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 UDF * 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 * Good coding practices in AutoIt * 

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: 2018-03-17

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

×