Jump to content

Login to a website failed using AutoIt script

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


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

If possible, share with me a working example.

Edited by Ganesh2VL

Share this post

Link to post
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

#Region ### START Koda GUI section ### Form=
$hMain = GUICreate("Test", 1015, 585, @DesktopWidth / 2 - $width / 2, @DesktopHeight / 2 - $height / 2, _

$wPos = WinGetPos($hMain)

#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


        Case $RunProgram

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


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()
EndFunc   ;==>Terminate


  • Like 1

Share this post

Link to post
Share on other sites

Moved to the appropriate forum.

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

Share this post

Link to post
Share on other sites

Thanks aa2zz6, your code works like a charm.



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


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.