Jump to content

Interact with "Save As" dialog


Recommended Posts

Hi all,

I'm trying to download a file as a result of an interrogation to a report server, this means I don't have a direct URL from which to download directly the file.

I need to interact with the classic "Save as" dialog box

saveas-2.thumb.png.23e3cf58291666b3d37d3

To perform this task I wrote a simple piece of code I'm supposed to work, it could be summarized as follows

Local $hWndDwnld=WinActivate("Download del file")
Sleep(500)
If @error Then
     ConsoleWrite('WinActivate' & '@error = ' & @error & @CRLF & '@extended = ' & @extended)
     ConsoleWrite("Wait for download file dialog..." & @CRLF)
     Local $hWndDwnld=WinWaitActive("Download del file")
     ConsoleWrite(".. found." & @CRLF)
     WinActivate($hWndDwnld)
Endif
;~ waiting for window
ControlSend($hWndDwnld, "", "", "!v")
;~ send ctrl+v

WinWait("Salva con nome")
WinActivate("Salva con nome")


ControlSetText("Salva con nome", "", "[CLASS:ToolbarWindow32; INSTANCE:3]", $dest)
Sleep(1500)
ControlSetText("Salva con nome","","[CLASS:Edit; INSTANCE:1]","")

Sleep(1500)
$filename="aReport.csv"
;~ ControlSetText("Salva con nome","&Salva","Edit1", $filename)
ControlSetText("Salva con nome","","[CLASS:Edit; INSTANCE:1]", $filename)
Sleep(1500)
$filename=ControlGetText("Salva con nome","&Salva","Edit1")
ConsoleWrite(" --> " & $filename & @CRLF)
ControlClick("Salva con nome","","Button1")

It's based mostly on this post: https://www.autoitscript.com/forum/topic/134561-automating-the-ie-save-as-file-dialog/

What I'would like to obtain is changing the filename and the directory as in the two variables $filename and $dest.

Instead I get the file named as provided by the report server and suggested at first in the SaveAs window and dowloaded in the last folder browsed, to be more clear none of the ControlSetText instructions in the snippet above work.

TIA for any help.

PS: the script is based on the Italian language settings for the WinOS, for the English language the "Download del file" and "Salva con nome" strings should be replaced by "File Download" and "Save As" respectively.

Edited by vladtsepesh
formatting
Link to comment
Share on other sites

Make your variables equal what ever you want them to be

$Dest = "C:/Server Reports/"

$FileName = "Server Report"

For the directory try ControlClicking the dest bar, then Send Crtl+A, then Send $Dest, then Send Enter.

For the filename try the same using the $FileName variable.

Granted I know this isn't in a code format but it should do what you want it to if you know how to use those commands.

 

Link to comment
Share on other sites

You might need to use a ControlSend for that control type.  (which is much worse than controlsettext, but this is one of the few times where it's necessary)

Would you get the handle of the window, and use it in my signature to get all the control outputs?  That might help get more info.

edit: I just tested on a save window for IE browser, and controlsettext works fine.  You probably aren't targeting the window or control properly.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

The ControlSend() command did the trick, but in advance I had to apply a Ctrl+a command to hilight all the default path a overwrite with the new one.

No need to interact with the [CLASS:ToolbarWindow32; INSTANCE:3] to move the foelder to the desired one.

WinWait("Salva con nome")
  Local $hSaveAsDlg=WinActivate("Salva con nome")

  ConsoleWrite(" --> full path" & $fullpathFileName & @CRLF)
  ControlSend($hSaveAsDlg,"&Salva","[CLASS:Edit; INSTANCE:1]","^a")
  ControlSend($hSaveAsDlg,"","[CLASS:Edit; INSTANCE:1]", $fullpathFileName)
  Sleep(1500)

  ConsoleWrite(" --> Click save Button " & @CRLF)
  ControlClick($hSaveAsDlg,"","Button1")

Thanks anybody.

Edited by vladtsepesh
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...