The trick to handle any dialogs is to use external tools like AutoIT to deal with the Upload dialog, download Dialog, and NTLM Authentication dialogs. Please note that this solution is intended only for users executing the scripts in Windows environment.
Using AutoIT you can write a simple script to get hold of the Save Dialog, this script can be then converted into an executable program with command line arguments to invoke it anytime from the program.
Following below steps should solve your issue.
- Download autoIT tool.
- Save the below-mentioned script to a
save_dialog.au3
file in the system.
- Open "
Compile Script to .exe
" program from AutoIT setup Directory.
- mention the path to
save_dialog.au3
and mention the path and name where you want to save .exe file. (lets say c:\save_ie_file.exe
)
- if you are using Java to write your automation code, use below lines of your code just before you click "download link" or expect a download dialog.
String[] dialog = new String[]{ "C:\\save_ie_file.exe","Save to...","Save", "C:\\selenium_downloads\\" }; // path to exe, dialog title, save/cancel/run, path to save file.
Process pp1 = Runtime.getRuntime().exec(dialog); // run the executable to wait for download link and process
selenium.click("id=download_link"); // code to click on download link
pp1.destroy(); // kill the process looking to download
save_dialog.au3 code blatantly Copied from here DISCLAIMER... I am not the author of that blog pointed in this answer:
AutoItSetOption("WinTitleMatchMode","2") ; set the select mode to select using substring
if $CmdLine[0] < 2 then
; Arguments are not enough
msgbox(0,"Error","Supply all the arguments, Dialog title,Run/Save/Cancel and Path to save(optional)")
Exit
EndIf
; wait Until dialog box appears
WinWait($CmdLine[1]) ; match the window with substring
$title = WinGetTitle($CmdLine[1]) ; retrives whole window title
WinActivate($title)
If (StringCompare($CmdLine[2],"Run",0) = 0) Then
WinActivate($title)
ControlClick($title,"","Button1")
EndIf
If (StringCompare($CmdLine[2],"Save",0) = 0) Then
WinWaitActive($title)
ControlClick($title,"","Button2")
; Wait for the new dialogbox to open
Sleep(2)
WinWait("Save")
$title = WinGetTitle("Save")
;$title = WinGetTitle("[active]")
if($CmdLine[0] = 2) Then
;click on the save button
WinWaitActive($title)
ControlClick($title,"","Button2")
Else
;Set path and save file
WinWaitActive($title)
ControlSetText($title,"","Edit1",$CmdLine[3])
ControlClick($title,"","Button2")
EndIf
EndIf
If (StringCompare($CmdLine[2],"Cancel",0) = 0) Then
WinWaitActive($title)
ControlClick($title,"","Button3")
EndIf