Created
June 29, 2012 06:51
-
-
Save srinivasa-pulagam/3016355 to your computer and use it in GitHub Desktop.
AutoIt script to automate IE9 file download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; sleep statements are added only to illustrate the focus on buttons | |
;read arguments | |
Local $pathToSave=$CmdLine[1] | |
; get the handle of main window | |
Local $windHandle=WinGetHandle("[Class:IEFrame]", "") | |
Local $winTitle = "[HANDLE:" & $windHandle & "]"; | |
;get coordinates of default HWND | |
Local $ctlText=ControlGetPos ($winTitle, "", "[Class:DirectUIHWND;INSTANCE:1]") | |
; wait till the notification bar is displayed | |
Local $color= PixelGetColor ($ctlText[0],$ctlText[1]) | |
while $color <> 0 | |
sleep(500) | |
$ctlText=ControlGetPos ($winTitle, "", "[Class:DirectUIHWND;INSTANCE:1]") | |
$color= PixelGetColor ($ctlText[0],$ctlText[1]) | |
wend | |
; Select save as option | |
WinActivate ($winTitle, "") | |
Send("{F6}") | |
sleep(500) | |
Send("{TAB}") | |
sleep(500) | |
Send("{DOWN}") | |
sleep(500) | |
Send("a") | |
; Save as dialog | |
; wait for Save As window | |
WinWait("Save As") | |
; activate Save As window | |
WinActivate("Save As") | |
; path to save the file is passed as command line arugment | |
ControlFocus("Save As","","[CLASS:Edit;INSTANCE:1]") | |
Send($pathToSave) | |
sleep(500) | |
;click on save button | |
ControlClick("Save As","","[TEXT:&Save]") | |
; wait till the download completes | |
Local $sAttribute = FileGetAttrib($pathToSave); | |
while $sAttribute = "" | |
sleep(500) | |
$sAttribute = FileGetAttrib($pathToSave) | |
wend | |
sleep(2000) | |
;close the notification bar | |
WinActivate ($winTitle, "") | |
Send("{F6}") | |
sleep(300) | |
Send("{TAB}") | |
sleep(300) | |
Send("{TAB}") | |
sleep(300) | |
Send("{TAB}") | |
sleep(300) | |
Send("{ENTER}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was really helpful.. but the problem I am facing is I cant seem to continue execution. Selenium gets stuck/hangs after the autoit scripts is done executing.
Code sample:
AutoItX x = new AutoItX();
x.sleep(2000);
x.winActivate("[HANDLE:" + x.winGetHandle("[Class:IEFrame]","") + "]");
check = x.winWaitActive("[HANDLE:" + x.winGetHandle("[Class:IEFrame]","") + "]", "", 15);
Thread.sleep(2000);
check = x.controlSend("[HANDLE:" + x.winGetHandle("[Class:IEFrame]","") + "]", "", "", "{F6}");
check = x.controlSend("[HANDLE:" + x.winGetHandle("[Class:IEFrame]","") + "]", "", "", "{TAB}");
check = x.controlSend("[HANDLE:" + x.winGetHandle("[Class:IEFrame]","") + "]", "", "", "{TAB}");
check = x.controlSend("[HANDLE:" + x.winGetHandle("[Class:IEFrame]","") + "]", "", "", "{ENTER}");
x.sleep(5000);
x.winClose("[HANDLE:" + x.winGetHandle("[Class:IEFrame]","") + "]","") + "]");
Could you please help.