Showing posts with label Web UI automation. Show all posts
Showing posts with label Web UI automation. Show all posts

Sunday, May 31, 2009

Part III - Order Placement

In Part II - Trade Signal Generation, we looked at how Buy/Sell sigal is generated in the following section I will explain how these signal is picked up and processed.

Here is the AutoIt script to achieve the purpose,




#include <IE.au3>
#include <String.au3>
#include <array.au3>
#Include <Date.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>
#include "myFunctions.au3"

;~ ; Set variables (read from database)
;~ ;Dim $myStartDateTime


Dim $Ticker, $iBasePrc, $chars, $isAliveCounter
$SIGNAL_TICKER_LIST = ""
$isAliveCounter = 0
$START_TIME = fnFetchConfigs("START_TIME") ; START_TIME
$UID = fnFetchConfigs("UID") ; $UID
$PWD = fnFetchConfigs("PWD") ; $PWD
$RUN_TIME = fnFetchConfigs("RUN_TIME") ; RUN_TIME
$CHUNK_AMT = fnFetchConfigs("CHUNK_AMT") ; CHUNK_AMT
$myStartDateTime = fnFetchConfigs("STARTED_AT") ; STARTED_AT ;-------------------- @YEAR & "/" & @MON & "/" & @MDAY & " " & $START_TIME


If $UID="" OR $START_TIME="" OR $RUN_TIME="" OR $CHUNK_AMT="" OR $myStartDateTime="" then
msgbox (0, "Alert", "Application variables are not set properly, EXIT'ing")
Exit
EndIf


If _DateTimeFormat( _NowCalc(), 5) > $START_TIME Then

WriteToLogFile ("New watch cycle Started.")


$minutesRemaining = _DateDiff ( 'n', $myStartDateTime, _NowCalc())

WHILE ($RUN_TIME - $minutesRemaining) >= 0


; this is debugging piece only..
$isAliveCounter = $isAliveCounter + 1
if $isAliveCounter > 360 Then
WriteToLogFile ("Watch cycle is alive.")
$isAliveCounter = 0 ;--reset the counter
EndIf
; debugging piece ends..


if fnSignalExists() > 0 Then

WriteToLogFile ("Signal found, initiating Order placement")
fnPlaceOrder()
WriteToLogFile ("Control returned to watching cycle")

EndIf

;==================================================
; moved to a seperate PlaceOrder function
;==================================================

Sleep(fnFetchConfigs("PLACE_ORDER_REFRESH")) ;Refresh every 5 seconds
$minutesRemaining = _DateDiff ( 'n', $myStartDateTime, _NowCalc())
$SIGNAL_TICKER_LIST = ""
;ConsoleWrite("Looping... " & $minutesRemaining & @CRLF)

WEND

WriteToLogFile ("End of watch cycle, system going to Sleep mode")
;Shutdown(32) ; put computer in Sleep mode

Else

WriteToLogFile ("Trading Session has not yet started!")

EndIf



Func fnPlaceOrder()

; Site login begins
WriteToLogFile ("Connecting to ICICI Direct.")

$oIE = fnOpenURL("https://secure.icicidirect.com/customer/logon.asp", "4000")
WriteToLogFile ("Logging-in to site.")

$oForm = _IEFormGetObjByName ($oIE, "loginform")
$oElement = _IEFormElementGetObjByName ($oForm, "FML_USR_ID")
_IEFormElementSetValue ($oElement, $UID)

$oElement = _IEFormElementGetObjByName ($oForm, "FML_USR_USR_PSSWRD")
_IEFormElementSetValue ($oElement, $PWD)

$oElement = _IEFormElementGetObjByName($oForm, "Submit1")
_IEAction ($oElement, "click")
Sleep(5000) ; some kind of IE context issue, looking for work around.
_IELoadWait ($oIE)

; Site login Ends

_IENavigate ($oIE, "https://secure.icicidirect.com/trading/equity/trading_basket_order.asp", 1)

;~ $oIE = _IEAttach ("ICICI direct.com :: Trading :: Basket Order", "title")

Sleep(2000)
_IELoadWait ($oIE)

WriteToLogFile ("Placing Order.")

$SplitTICKER_LIST = StringSplit(fnFetchSignalTickerList(), "?")

For $i = 1 to UBound($SplitTICKER_LIST, 1)-2

$OrderValues = StringSplit($SplitTICKER_LIST[$i], "")

$iBasePrc = Round(Number($OrderValues[2]), 1)

If $iBasePrc <> "" Then

$iQty = Int($CHUNK_AMT/$iBasePrc)

if $iQty * $iBasePrc < $CHUNK_AMT then $iQty = $iQty+1

$oForm = _IEFormGetCollection ($oIE, 1)

$oElement = _IEFormElementGetObjByName ($oForm, "FML_ORD_XCHNG_CD" & $i) ; Exchange
_IEFormElementOptionSelect ($oElement, "NSE", 1, "byText")

$oElement = _IEFormElementGetObjByName ($oForm, "FML_ORD_PRDCT_TYP" & $i) ; Product
_IEFormElementOptionSelect ($oElement, "CASH", 1, "byText")

$oElement = _IEFormElementGetObjByName ($oForm, "FML_ACTION" & $i) ; Action
_IEFormElementOptionSelect ($oElement, $OrderValues[3], 1, "byText")

$oElement = _IEFormElementGetObjByName ($oForm, "FML_STCK_CD" & $i) ; Ticker/Stock
_IEFormElementSetValue ($oElement, $OrderValues[1])

$oElement = _IEFormElementGetObjByName ($oForm, "FML_QTY" & $i) ; Quantity
_IEFormElementSetValue ($oElement, $iQty)

_IEFormElementRadioSelect ($oForm, "L", "FML_ORD_TYP" & $i, 1, "byValue")

$oElement = _IEFormElementGetObjByName ($oForm, "FML_ORD_LMT_RT" & $i) ; Limit price
_IEFormElementSetValue ($oElement, $iBasePrc)

fnWriteToDB("update ICICI_Signal set SignalActive = 0 where SignalActive = 1 and SignalTicker='"& $OrderValues[1] &"';")
WriteToLogFile ("Buy signal is de-activitated for " & $OrderValues[1])

$iBasePrc = ""
$Ticker = ""

EndIf
Next ; $i



;~ it was wasting some time so disabled it
;~ ;Take screenshot after basket it filled
;~ WriteToLogFile ("Order form screenshot - " & TakeScreenShot("ICICI direct.com :: Trading :: Basket Order"))
;~ Sleep(1000)

WriteToLogFile ("Order form submitted")
$oElement = _IEFormElementGetObjByName ($oForm, "Submit")
_IEAction ($oElement, "click")
Sleep(2000)
_IELoadWait ($oIE)


;===== Confirmation window
$oForm = _IEFormGetCollection ($oIE, 1)

$oElement = _IEFormElementGetObjByName ($oForm, "CheckUnCheck")
_IEAction ($oElement, "click")

WriteToLogFile ("Order confirmation screenshot - " & TakeScreenShot("ICICI direct.com :: Trading :: Basket Order Verification"))

$oElement = _IEFormElementGetObjByName ($oForm, "Submit_Butt")
_IEAction ($oElement, "click")
Sleep(2000)
WriteToLogFile ("Order Confirmation done.")

_IELoadWait ($oIE)
WriteToLogFile ("Confirmation submitted screenshot - " & TakeScreenShot("ICICI direct.com :: Trading :: Basket Order Acknowledgement"))
;===== Confirmation window Ends


;~ msgbox (0, "CAUTION", "Hard exit ! next")
;~ Exit



; signing out
WriteToLogFile ("Signing out.")
fnClickOnLink ("Logout", $oIE)
sleep(7000)
WinActivate("Windows Internet Explorer")
sleep(1000)
SendKeepActive("Windows Internet Explorer")
Send("{ENTER}")
_IEQuit ($oIE)
WriteToLogFile ("Exiting PlaceOrder function.")

EndFunc




As I said before I am not going to explain this script in plain english as its already simple, this is the reason I recommend AutoIt as the best hobbyist programmer language

What about the order quantity ? - The order quantity is based on CHUNK_AMOUNT variable set in ICICI_Configs table. It will check how many units it can buy with
CHUNK_AMOUNT/OrderPrice rounded off to integer. This allows buying any stock in chunks rather than in one single go.

Ones the order placement is done it will update the YstClosingQuote value for the respective ticker/symbol. Look at ICICI_Log table screenshot in Part II to get better understanding on sequence of activities.

Part II - Trade Signal Generation

By now you know how the database is layed out. In the following parts you will be mostly dealing with AutoIt script which intracts with market data and my database with configurations and watch list.

I will put all of the source code here instead of explaining it in plain english. Since the AutoIt is BASIC like language it easy to understand.





#include <ie.au3>
#include <string.au3>
#include <array.au3>
#Include <date.au3>
#include <sqlite.au3>
#include <sqlite.dll.au3>
#include "myFunctions.au3"
#include <winhttp.au3>


; Set variables (read from database)
$START_TIME = fnFetchConfigs("START_TIME") ; START_TIME
$TICKER_LIST = fnFetchTickerList() ; TICKER_LIST
$REFRESH_INTERVAL = fnFetchConfigs("REFRESH_INTERVAL") ; REFRESH_INTERVAL
$RUN_TIME = fnFetchConfigs("RUN_TIME") ; RUN_TIME
$myStartDateTime = fnFetchConfigs("STARTED_AT") ; STARTED_AT
;-------------------- @YEAR & "/" & @MON &
; "/" & @MDAY & " " & $START_TIME

If _DateTimeFormat( _NowCalc(), 5) > $START_TIME Then

$MinutesSinceStarted = _DateDiff ( 'n', $myStartDateTime, _NowCalc())
WriteToLogFile ("Started capturing quotes.")

Dim $iBasePrc, $chars, $QuoteFileName
Dim $AppEndDateTime, $QuoteString

while ($RUN_TIME - $MinutesSinceStarted) >= 0

;split the $TICKER_LIST and get quotes for all the tickers in the list
$SplitTICKER_LIST = StringSplit($TICKER_LIST, "")

for $i = 1 to UBound($SplitTICKER_LIST, 1)-1

$TICKER = $SplitTICKER_LIST[$i]
;msgbox (0, $i, $SplitTICKER_LIST[$i])

$QuoteString = fnHTTP_GetQuote($SplitTICKER_LIST[$i])

if StringLen($QuoteString) > 10 Then

$QuoteArray = _StringSplit($QuoteString, "")

$CurrentQuote = StringReplace ($QuoteArray[2], ",", "")
$myTime = $QuoteArray[0] & " " & $QuoteArray[1]

$iBasePrc = Number($iBasePrc)
$CurrentQuote = Number($CurrentQuote)

fnWriteToDB ("UPDATE ICICI_WatchList SET &_ CurrentQuote = "& $CurrentQuote &", &_
LocalDateTime = CURRENT_TIMESTAMP WHERE Ticker = '" & $TICKER & "';")
;ConsoleWrite ("Quotes updated.." & @CRLF)

$iBasePrc = ""
$QuoteString=""
$chars = ""

Else

WriteToLogFile ("HTTP Request might have failed!")

EndIf

NEXT ;$i

;interval
sleep ($REFRESH_INTERVAL) ; every 20 seconds..
$MinutesSinceStarted = _DateDiff ( 'n', $myStartDateTime, _NowCalc())
;ConsoleWrite($RUN_TIME - $MinutesSinceStarted & @CRLF)

wend

WriteToLogFile ("End of trading session.")
;Shutdown(32) ; put computer in Sleep mode

Else

WriteToLogFile ("Trading session not yet started.")

EndIf

Exit
;====================================================================================================





Func fnHTTP_GetQuote($Ticker)

Dim $TradeDate, $TradeTime, $LatestQuote

$hw_open = _WinHttpOpen()
$hw_connect = _WinHttpConnect($hw_open, "getquote.icicidirect.com")
$h_openRequest = _WinHttpOpenRequest($hw_connect, "GET", "/trading/equity/trading_stock_quote.asp?Symbol=" & $Ticker)

_WinHttpSendRequest($h_openRequest)
_WinHttpReceiveResponse($h_openRequest)

If _WinHttpQueryDataAvailable($h_openRequest) Then
$data = ""
While 1
$chunk = _WinHttpReadData($h_openRequest, 1)
If Not @extended Then ExitLoop
;ConsoleWrite($chunk & @CRLF)
$data &= $chunk
WEnd

;ConsoleWrite($data & @CRLF)
;msgbox (0, "StringLen($data)", StringLen($data))
;-- error stringLen 7808
;-- good stringLen 12995

If StringLen($data) > 10000 Then ; good request return

;=========== LAST TRDED DATE START ================
;First cut
$mySubString = "DATE"
$StartAt = StringInStr($data, $mySubString)
$TradeDate = StringMid($data, $StartAt, 200)

;Second cut
$mySubString = ""
$StartAt = StringInStr($TradeDate, $mySubString)
$TradeDate = StringMid($TradeDate, $StartAt, 200)

;Third cut
$mySubString = ">"
$StartAt = StringInStr($TradeDate, $mySubString)
$TradeDate = StringMid($TradeDate, $StartAt+1, 200)

;Fourth cut
$mySubString = ""
$EndAt = StringInStr($TradeDate, $mySubString)
$TradeDate = StringMid($TradeDate, 1, $EndAt-1)

;msgbox (0, "Last Trade Date", $TradeDate)
;=========== LAST TRDED DATE ENDS ================


;=========== LAST TRDED TIME START ================
;First cut
$mySubString = "LAST TRADED "
$StartAt = StringInStr($data, $mySubString)
$TradeTime = StringMid($data, $StartAt, 200)

;Second cut
$mySubString = ""
$StartAt = StringInStr($TradeTime, $mySubString)
$TradeTime = StringMid($TradeTime, $StartAt, 200)

;Third cut
$mySubString = ">"
$StartAt = StringInStr($TradeTime, $mySubString)
$TradeTime = StringMid($TradeTime, $StartAt+1, 200)

;Fourth cut
$mySubString = ""
$EndAt = StringInStr($TradeTime, $mySubString)
$TradeTime = StringMid($TradeTime, 1, $EndAt-1)
;msgbox(0, "Latest Trde Time", $TradeTime)
;=========== LAST TRDED TIME ENDS ================


;~ ;=========== LASTEST QUOTES STARTS ================
;First cut
$mySubString = " LAST TRADE "
$StartAt = StringInStr($data, $mySubString)
$LatestQuote = StringMid($data, $StartAt, 200)

;Second cut
$mySubString = ""
$StartAt = StringInStr($LatestQuote, $mySubString)
$LatestQuote = StringMid($LatestQuote, $StartAt, 200)

;Third cut
$mySubString = ">"
$StartAt = StringInStr($LatestQuote, $mySubString)
$LatestQuote = StringMid($LatestQuote, $StartAt+1, 200)

;Fourth cut
$mySubString = ""
$EndAt = StringInStr($LatestQuote, $mySubString)
$LatestQuote = StringMid($LatestQuote, 1, $EndAt-1)
;msgbox(0, "Latest Quoted", $LatestQuote)
;~ ;=========== LASTEST QUOTES ENDS ================
EndIf

EndIf

_WinHttpCloseHandle($h_openRequest)
_WinHttpCloseHandle($hw_connect)
_WinHttpCloseHandle($hw_open)

;ConsoleWrite ($TradeDate & "" & $TradeTime & "" & $LatestQuote & @CRLF)

Return($TradeDate & "" & $TradeTime & "" & $LatestQuote)

EndFunc





This above code is the one which captures the ticker/stock price and writes it to the ICICI_Watchlist >> CurrentQuote column. As soon as the column is updated
with new price the trigger on that table fires up and checks if the price is
closer by the expected target price (QuoteVariance), if yes it will generate
a signal.

Is the signal buy or sell ? - this depends on QuoteVariance. If QuoteVariance
is set as minus that means you are looking for price going lower and lower, so
BUY signal is generated for PreviousClosing-(PreviousClosing*QuoteVariance)

Similarly if the you are looking to sell your holdings if price goes above +5% (QuoteVariance) of previous day closing then SELL signal is generated

In the next part, I will explain how this signal is processed and order is actual placed.

Saturday, December 27, 2008

Automated Trading - interesting

I have an account with folioinvesting (earlier known as foliofn). They have a system of window trading i.e. you can place your order during that window trading period and those trades are less expensive - refer to their site for more. But I wanted to place window orders at 8 am and 11 am. There are many times when I am office or in transit so I used to miss it. Also automation makes the timing more accurate. Then I decided to automate it, so wrote this script. This script demonstrates (apart from logging in) clicking of links, selecting radio buttons and clicking on specified images. When I say clicking not just clicking randomly here and there, but to accomplish this task of placing an window order. To place a window order in foliofn it takes about 10 mouse clicks and going through 3-4 screens, more than that its the timing that is important. So, I wrote this script and scheduled it - problem solved. It also generates the log as well.I have added some customizations to suite my requirements


Currently this script places orders blindly, I mean it runs at scheduled time and places the order, the scope of improvement is - it should be intelligent enough to decide whether to place or not or when to place 8 AM or 11 AM or both ?? -- I am working on it :)




#Include <Date.au3>
#include <IE.au3>

Dim $Filename

WriteToLogFile ("foliofn_log.txt", "Connecting to Foliofn...")

ShellExecute("C:\Program Files\Internet Explorer\IEXPLORE.EXE", "about:blank")

Sleep (3000)

$oIE = _IEAttach ("about:blank", "url")

Sleep (2000)

_IENavigate ($oIE, "https://www.folioinvesting.com/servlets/ProcessAction?identifier=loginFormEntry&click1=Login")

_IELoadWait ($oIE)

$oForm = _IEFormGetObjByName ($oIE, "loginForm")

$oElement = _IEGetObjById($oIE, "inputLogin")
_IEFormElementSetValue ($oElement, "user_id")

$oElement = _IEGetObjById($oIE, "inputPassword")
_IEFormElementSetValue ($oElement, "********")

$oElement = _IEGetObjById($oIE, "loginBtn")
_IEAction ($oElement, "click")

WriteToLogFile ("foliofn_log.txt", "Logged-in to Foliofn")

_IELoadWait ($oIE)

WriteToLogFile ("foliofn_log.txt", "Started Placing Order")

_IENavigate ($oIE, "https://www.foliofn.com/servlets/ProcessAction? &_
identifier=default_myAccounts_portal&myAcct.destination=tradeWindow& &_
;myAcct.level=F&myAcct.accountname=*****&myAcct.accountType &_
=I&myAcct.accountNumber=********&myAcct.folioNumber=**********") &_
_IELoadWait ($oIE)


WriteToLogFile ("foliofn_log.txt", "Opening - [Trade Entire Folio] Tab")

;Find the link "Trade Entire Folio" and click it
$sMyString = "Trade Entire Folio"
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
$sLinkText = _IEPropertyGet($oLink, "innerText")
If StringInStr($sLinkText, $sMyString) Then
_IEAction($oLink, "click")
ExitLoop
EndIf
Next

_IELoadWait ($oIE)


WriteToLogFile ("foliofn_log.txt", "Opening - [Update & Exchange] Tab")

;Find the link "Update & Exchange" and click it

$sMyString = "Update & Exchange"
$oLinks = _IELinkGetCollection($oIE)
For $oLink in $oLinks
$sLinkText = _IEPropertyGet($oLink, "innerText")
If StringInStr($sLinkText, $sMyString) Then
_IEAction($oLink, "click")
ExitLoop
EndIf
Next

_IELoadWait ($oIE)

WriteToLogFile ("foliofn_log.txt", "Making final selections")

; Select RADIO button
$oForm = _IEFormGetObjByName ($oIE, "tradeFolioSyncSubmit")
_IEFormElementRadioSelect ($oForm, "R", "syncOption", 1, "byValue")


;Preview Order : remember it's an image button
_IEFormImageClick ($oIE, "btn_preview.gif", "src")
_IELoadWait ($oIE)

WriteToLogFile ("foliofn_log.txt", "Clicked on order PREVIEW button")


;Preview Order : remember it's an image button
_IEFormImageClick ($oIE, "btn_order.gif", "src")

WriteToLogFile ("foliofn_log.txt", "Clicked on [Place Order] button")

_IELoadWait ($oIE)

WriteToLogFile ("foliofn_log.txt", "Order Placed")


WriteToLogFile ("foliofn_log.txt", "Loging-out of the site..")

_IEImgClick ($oIE, "/_linkedfiles/_images/_ui/icon_logout.gif", "src")
sleep(1000)
_IELoadWait ($oIE)

_IEQuit ($oIE)

If _NowTime(5) > '10:58:00' Then
WriteToLogFile ("foliofn_log.txt", "Putting the computer in Sleep mode !")
Shutdown(32)
EndIf

WriteToLogFile ("foliofn_log.txt", "===================================")

;-- Order Placed..

;==============================================
; Logging function
Func WriteToLogFile ($Filename, $Contents)
$file = FileOpen($Filename, 1)
FileWriteLine($file, @ScriptName & @TAB & _Now() & @TAB & $Contents & @CRLF )
FileClose($file)
EndFunc
;==============================================



How to navigate through a web page and fetch data ?

Have you ever done clicking and moving mouse across 2-3 pages just to get one small piece of information. Now with on click you can browse through multiple pages and get the piece of info that you are looking for. Here, in this example I'll show you how to get the exchange rate of INR/USD and save that value into an txt file. This is for education purpose only. Stripping data from others website may be violation of law and in some cases frequent automated browsing migh bring down the site as well.




#include <IE.au3>
#include <String.au3>
#include <array.au3>
#Include <Date.au3>



Dim $iBasePrc, $chars, $QuoteFileName
$QuoteFileName = "Currency_" & @YEAR & ".txt"


$oIE = fnOpenURL("http://www.xe.com/ucc/", "3000")


; Initialize $sHTML value
$sHTML = _IEDocReadHTML ($oIE)


if StringLen($sHTML) > 1000 Then


$oForm = _IEFormGetObjByName ($oIE, "ucc")
$oSelect = _IEFormElementGetObjByName ($oForm, "From")
_IEFormElementOptionSelect ($oSelect, "United States Dollars - USD", 1, "byText")
$oSelect = _IEFormElementGetObjByName ($oForm, "To")
_IEFormElementOptionSelect ($oSelect, "India Rupees - INR", 1, "byText")
;Click on Submit image button
_IEFormImageClick ($oIE, "/gen/images/btn_go.gif", "src")
_IELoadWait ($oIE)
;now you are on rates page
$oTable = _IETableGetCollection ($oIE, 12)
$aTableData = _IETableWriteToArray ($oTable, True)
$myQuote = StringReplace($aTableData[2][2], "INR", "")
$myTime = _NowCalc();StringReplace($aTableData[1][0], "Live rates at ", "")
fnWriteToFile($QuoteFileName, $myTime & @TAB & $myQuote, "")


EndIf


_IEQuit ($oIE)



Func fnOpenURL($myURL, $AttachDelay)


ShellExecute ("C:\Program Files\Internet Explorer\iexplore.exe", "about:blank")
if $AttachDelay < 3000 Then $AttachDelay=3000;3 seconds
Sleep ($AttachDelay)
$oIE = _IEAttach ("about:blank", "url")
_IENavigate ($oIE, $myURL)
_IELoadWait ($oIE)
return($oIE)


EndFunc



Func fnWriteToFile($fileName, $Content, $TimeStamp)


$file = FileOpen($fileName, 1)
if $TimeStamp <> "" Then FileWriteLine($file, _NowCalc() & @TAB & $Content & @CRLF)
if $TimeStamp = "" Then FileWriteLine($file, $Content & @CRLF)


EndFunc


Saturday, December 13, 2008

Generic Web User Interface Login Automation


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



Testing Google Search Results

Twin Star Adjustable Height Desk, White (ODP1055548D908) https://www.costcobusinessdelivery.com/Twin-Star-Adjustable-Height-Des...