Selenium: File download handling.
When we download any file from internet, browser opens new pop-up windows and prompt user for action. Action could be open, save or save as. Pop-up windows ( GUI ) could be different based on browser.
When you are automating file download dialog box (or action), you should keep following points in mind.
- Browser
- Pop-up windows title
- Pop-up GUI
- Available buttons on GUI
- File Type (Binary file, zip file, MS file etc..)
- Extra settings
See how IE and FF pop-ups ...
![]() |
![]() |
![]() |
![]() |
![]() |
If you have any doubt or if it is not working , please provide me details and I will try to fix the problem.
Func Down_FF_NonMS()
Send("{TAB}{TAB}{ENTER}")
WinClose ( "Downloads" )
EndFunc
Func Down_FF_MS()
;MsgBox(0, "FF", "in Down_FF_MS function")
Send("!S")
Send("{TAB}{TAB}{TAB}{ENTER}")
EndFunc
Func Down_IE_MS($file)
$var = EnvGet("SWGHOME");
$file2 = $var & "\tmp\" & $file
;MsgBox(0, "AutoIt Example", $file2)
Send("!s")
Send($file2)
Send("!s")
if ( WinWait("Save As") ) Then
Send("{TAB}{ENTER}")
EndIf
EndFunc
$Total = $CmdLine[0];
;MsgBox(0, "FF", "Total " & $Total )
$File = $CmdLine[1];
$Browser = $CmdLine[2];
$FileType = $CmdLine[3];
;MsgBox(0, "FF", "Total " & $Total & $File & " " & $Browser & " " &$FileType)
;$File = "1.exe"
;$File = "goodword.doc"
;$Browser = 2
;$FileType = 2
If $Browser = 1 Then ; 1 = FF 2 = IE
; MsgBox(0, "FF", $File)
winWait("Opening " & $File);
;MsgBox(0, "FF", $File)
WinActivate("Opening " & $File);
if $FileType = 0 Then ; 0= MS files 1= Non MS file
Down_FF_MS();
Else
Down_FF_NonMS();
EndIf
Else
;MsgBox(0, "IE", $File)
winWait("File Download");
WinActivate("File Download" );
Down_IE_MS($file);
EndIf
WinClose ( "Downloads" )
How to Run AutoIT script.
create exe filedownlaod.exe file from above code. (AutoIT can generate exe file from au3 script file.)
c:\filedownload.exe 1 1
c:\filedownload.exe "file to be downloded" "browser FF/IE" "File Type MS/Non/MS"
where FF browser = 1 and IE = 2
MS file type = Doc,ppt,pdf... = 0
Non MS File type exe,com.... = 1
Comments
Post a Comment