This script works for most of web login screens like hotmail.com, mail.yahoo.com, gmail.com etc. It picks up most of the configuration values from associated ini file, in this case it depends on "myfile.ini". If you want to automate loging in to other sites like comcast, AT & T you just add another section in the INI file with detail of the web UI objects
Contents of AutoIt script
#Include <Date.au3>
#include <IE.au3>
$varSec = IniReadSectionNames("myfile.ini")
If @error Then
MsgBox(4096, "", "Error occurred, You have not set the INI file.")
Else
For $i = 1 To $varSec[0]
WriteToLogFile ("Logged in user name " & @UserName)
WriteToLogFile ("Opening " & $varSec[$i] & " page.")
ShellExecute("C:\Program Files\Internet Explorer\IEXPLORE.EXE", "about:blank")
Sleep (3000)
$oIE = _IEAttach ("about:blank", "url")
Sleep (2000)
_IENavigate ($oIE, fnGetKeyValue($varSec[$i], "url"))
_IELoadWait ($oIE)
$oForm = _IEFormGetObjByName ($oIE, fnGetKeyValue($varSec[$i], "form"))
$oElement = _IEGetObjById($oIE, fnGetKeyValue($varSec[$i], "uInput"))
_IEFormElementSetValue ($oElement, fnGetKeyValue($varSec[$i], "uid"))
$oElement = _IEGetObjById($oIE, fnGetKeyValue($varSec[$i], "pInput"))
_IEFormElementSetValue ($oElement, fnGetKeyValue($varSec[$i], "pwd"))
if fnGetKeyValue($varSec[$i], "btn") <> "" Then
$oElement = _IEGetObjById($oIE, fnGetKeyValue($varSec[$i], "btn"))
_IEAction ($oElement, "click")
Else
_IEFormSubmit ($oForm)
EndIf
_IELoadWait ($oIE)
WriteToLogFile ("Signed in to " & $varSec[$i] & ".")
_IELoadWait ($oIE)
WriteToLogFile ("Inbox opened for " & $varSec[$i] & ".")
WriteToLogFile ("---------------------------------------------------")
Next
EndIf
; Get key values suing section name
Func fnGetKeyValue ($Section, $Key)
$varKeys = IniReadSection("myfile.ini", $varSec[$i])
For $j = 1 To $varKeys[0][0]
;MsgBox(4096, "", "Key: " & $varKeys[$j][0] & @CRLF & "Value: " & $varKeys[$j][1])
if $varKeys[$j][0] = $Key Then
Return ($varKeys[$j][1])
EndIf
Next
EndFunc
; Logging function
Func WriteToLogFile ($Contents)
$file = FileOpen(@ScriptName & "_log.txt", 1)
FileWriteLine($file, _Now() & @TAB & $Contents & @CRLF )
FileClose($file)
EndFunc
Contents of myfile.ini
[Yahoo]
url=http://www.mail.yahoo.com
form=login_form
uInput=username
pInput=passwd
uid=user id goes here
pwd=password goes here
btn=.save
[Hotmail]
url=http://www.hotmail.com
form=f1
uInput=i0116
pInput=i0118
uid=user id goes here@hotmail.com
pwd=password goes here
btn=idSIButton9
[Gmail]
url=http://www.gmail.com/
form=gaia_loginform
uInput=Email
pInput=Passwd
uid=user id goes here
pwd=password goes here
btn=signIn
No comments:
Post a Comment