Jump to content

Login to a website failed using AutoIt script


 Share

Recommended Posts

Dear All,

I am trying to login to website using AutoIT script but its failed, throwing the below error msg.

"Return SetError($_IESTATUS_Success, 0, $oObject.document)"

"Error: The requested action with this object has failed"

 

Please check my below code:

Func MyFunc()
Local $sUsername = "***"
Local $sPassword = "***"
$sUrl = "http://appName:8005/OA_HTML/RF.jsp"
$oIE = _IECreate($sUrl, 0, 1, 0, 1)
Sleep(2000)
$oHWND = _IEPropertyGet($oIE, "hwnd")
WinSetState($oHWND, "", @SW_MAXIMIZE)
$oForm = _IEFormGetCollection($oIE, 0)
$oUsername = _IEFormElementGetObjByName($oForm, 'unamebean') ; change name !
$oPassword = _IEFormElementGetObjByName($oForm, "pwdbean") ; change name !
_IEFormElementSetValue($oUsername, $sUsername)
_IEFormElementSetValue($oPassword, $sPassword)
; This is my custom defined error handler
_IEFormSubmit($oForm)
EndFunc

 

Please advise why the above failed, what is the cause of this issue.

If possible, share with me a working example.

Edited by Ganesh2VL
Link to comment
Share on other sites

Sorry, I don't have time to test yours but I'll post a working script below that I've used in the past. Revise the ID name and password accordingly and let us know if you have any questions. 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <GDIPlus.au3>

;#Escape program
HotKeySet("{ESC}", "Terminate")

Local $iWidthCell = 70 ;#GUI Create
$width = 800 ;#GUI Create
$height = 625 ;#GUI Create

Global $x ;#Func Email
Global $y ;#Func Password


_IEErrorHandlerRegister()
#Region ### START Koda GUI section ### Form=
$hMain = GUICreate("Test", 1015, 585, @DesktopWidth / 2 - $width / 2, @DesktopHeight / 2 - $height / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)

$wPos = WinGetPos($hMain)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;#Input Email
GUICtrlCreateLabel("Email:", 880, 65, $iWidthCell)
$hInput1 = GUICtrlCreateInput("", 880, 90, 85, 20)
;#Input Password
GUICtrlCreateLabel("Password:", 880, 115, $iWidthCell)
$hInput2 = GUICtrlCreateInput("", 880, 140, 85, 20)

;#Initializes the IE Explore
Local $RunProgram = GUICtrlCreateButton("Run Program", 880, 170, 85, 25)

;#IE Create
Func internet()
    Local $oIE = _IECreateEmbedded()

    GUICtrlCreateObj($oIE, 0, 0, $width + 0, $height + 0)
    _IENavigate($oIE, "https://www.facebook.com/?_rdr=p")

    Local $username = _IEGetObjByName($oIE, "email")
    Local $password = _IEGetObjByName($oIE, "pass")
    Local $button = _IEGetObjByName($oIE, "u_0_x")

    _IEFormElementSetValue($username, $x)
    _IEFormElementSetValue($password, $y)
    ;$oBtn = _IEGetObjById($oIE, "u_0_x") ; works on the main login page
    ;$oBtn = _IEGetObjById($oIE, "u_0_2") ; works on the second login page
    ;   _IEAction($oBtn, "click")
EndFunc   ;==>internet

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE, $idClose

            ExitLoop

        Case $RunProgram

            $x = GUICtrlRead($hInput1)
            $y = GUICtrlRead($hInput2)
            internet()
    EndSwitch

WEnd

Func Email($x)
    $x = ControlGetText(WinGetTitle("[AutoIt v3 GUI]"), "", "[CLASS:Edit; INSTANCE:1]")
EndFunc   ;==>Email

Func Password($y)
    $y = ControlGetText(WinGetTitle("[AutoIt v3 GUI]"), "", "[CLASS:Edit; INSTANCE:2]")
EndFunc   ;==>Password

Func Terminate()
    Exit
EndFunc   ;==>Terminate

 

Link to comment
Share on other sites

  • 2 weeks 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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...