Skip to content

Instantly share code, notes, and snippets.

@srinivasa-pulagam
Created June 29, 2012 06:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save srinivasa-pulagam/3016355 to your computer and use it in GitHub Desktop.
Save srinivasa-pulagam/3016355 to your computer and use it in GitHub Desktop.
AutoIt script to automate IE9 file download
; 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}")
@ff-akhilr
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment