Jump to content
Sign in to follow this  
vladtsepesh

Interact with "Save As" dialog

Recommended Posts

vladtsepesh

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

Share this post


Link to post
Share on other sites
xxaviarxx

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.

 

Share this post


Link to post
Share on other sites
ViciousXUSMC

ControlSend() should work for you in most cases to put your strings in, then ControlClick() to click the Save button. 

If not IUIAutomation will surely work. 

Share this post


Link to post
Share on other sites
jdelaney

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
  • Like 1

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.

Share this post


Link to post
Share on other sites
vladtsepesh

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

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello
      Can we pause and resume the download in the InetGet function?
      If is possible, what is the solution please?
      I used this code To manage the download

      #include <INet.au3> func _downloader($name, $linc, $filepath, $RTLF = false, $link = false) global $downloader = GUICreate("downloader", 400, 200, -1, -1, $WS_CLIPCHILDREn, $RTLF, $link) global $path = $filePath $labelTxt = GUICtrlCreateLabel("downloading " & $name, 50, 10, 200, 20) global $labelTxt0 = GUICtrlCreateLabel("downloaded size 0 MB " & "OF 0 MB", 50, 60, 300, 20) global $Progress = "" global $sText = ""     For $i = 1 To Random(5, 20, 1) ; Return an integer between 5 and 20 to determine the length of the string.         $sText &= Chr(Random(65, 122, 1)) ; Return an integer between 65 and 122 which represent the ASCII characters between a (lower-case) to Z (upper-case). next global $labelTxt2 = GUICtrlCreateInput("0%", 50, 80, 50, 20) _GUICtrlEdit_SetReadOnly(-1, true) GUIStartGroup("") global $beep = GUICtrlCreateCheckBox("use the progress beep notification", 150, 120, 200, 20) GUIStartGroup("") $button = GUICtrlCreateButton("Cancel', 130, 150, 180, 25, 0x01) $iIndex = 0 global $Target global $url GUIStartGroup("") global $Progress = GUICtrlCreateProgress(50, 90, 150, 20) global $Target = $filepath global $url = $linc global $path = $filepath global $hDownloadNo = _RSMWare_GetData($url, $Target) global $status = false AdlibRegister("SetProgress") global $onprogress = false, $curent = false GUISetState(@sw_Show) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $button $asc = MsgBox(4132,"exit download?","if you click yes the downloading will be cancel, do you want to cancel it ?") if $asc = 6 then AdlibUnRegister("SetProgress") GUIDelete() If $hDownloadNo <> 0 Then InetClose($hDownloadNo) exitLoop endIf EndSwitch if $status = -1 then $status = 0 $hDownloadNo = _RSMWare_GetData($url, $Target) $onprogress = false $curent = false elseIf $Status = 1 then $status = $path GUIDelete() AdlibUnRegister("SetProgress") exitLoop endIf WEnd return $status endFunc Func _RSMWare_GetData($url, $Target) Local $hDownload = InetGet($url, $Target, 1, 1) Return $hDownload EndFunc ;==>_RSMWare_GetData Func SetProgress() Local $state If $hDownloadNo <> 0 Then $state = InetGetInfo($hDownloadNo) If @error = 0 Then $infor = "downloaded size " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADREAD) / 1048576), 2) & " MB of " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) / 1048576), 2) & " MB " $onprogress = Round(Ceiling(($state[0] / $state[1]) * 100)) if not (InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) = 0) then if $onProgress <= 0 then $onProgress = 0 GUICtrlSetData($Progress, $onProgress) GUICtrlSetData($labelTxt0, $infor) GUICtrlSetData($labelTxt2, $onProgress & "%") if _isChecked($beep) then if $onprogress > $curent then beep((100 + $onprogress * 20), 100) $curent = $onprogress endIf endIf endIf If $state[2] Then If $state[3] Then InetClose($hDownloadNo) $status = 1 else InetClose($hDownloadNo) $status = -1 endIf endIf EndIf endIf EndFunc ;==>SetProgress
    • tintin92
      By tintin92
      Hello,

      How can I automatically download a list of zip files, like the ones in the quote, using a AutoIt script?
      Is it possible with AutoIt script?
       
    • UEZ
      By UEZ
      Here a small tool I wrote to update my Sysinternal tools collection without the need to download always the whole package or visiting the site to check for updates. I know that there are several tools available (also some tools written in AutoIt) but here another one for the collection. It was good exercise for me to code it.
       
       
        
       
       
      Some files from cannot be downloaded although they are visible on the web site!
       
      Here the download link of the source code only: AutoIt Sysinternal Tools Synchronizer v0.99.1 build 2017-10-23 beta.7z  (1353 downloads previously)
      -=> Requires AutoIt version 3.3.13.20 or higher / tested on Win8.1 real machine and some VMs: Win7 / Vista / Win10
       
      Compiled exe only: @MediaFire
       
      Just select the Sysinternal Tools folder or create one and press the synchronize button to download the selected items. Click on AutoIt label (near to left upper corner) to open menu.
       
      Special thanks to LarsJ, Melba23 and mesale0077 for their help. 
       
      I've still some ideas to implement which are more gimmick related, so it is not finished yet...
      If you want to add your language please check out #Region Language. Thanks. 
       
      Please report any bug or if you have any suggestions.
       
      The language of the tool tip from each of the executable in the left list view were automatically created using Google translator and weren't checked for correctness.
       
      Br,
      UEZ
    • TotalAuto
      By TotalAuto
      Hi All
      I am new to AutoIT, its community, and pretty much programming in general. 
      After a bit of online research, I decided to focus on AutoIT as my first programming attempt as it seems quite powerful and amazing once you become advanced at it. I have read some introductory pdfs which where good, including from the guy I think who invented it. I also watched various sketchy youtube videos, checked out the forum etc. I have to admit it's a bit confusing starting off but I reckon if I just keep pushing forward with continual hard work I can only get better.  
      My first AutoIT project has been to open Internet Explorer and automatically log into Twitter to save doing it manually. I plan to run this after windows start up via task scheduler. I am using the #include <IE.au3> UDF but for some reason about 20% of the time I receive the following orange error notifications at the bottom of the editor (pic attached). When it happens the IE browser just doesn't open but the program continues to run which mucks up the script. 
      Does anyone know why this is happening and how it can be fixed? Also is there some other better, less error prone way, to open IE and automatically log in?
      I have tried to use the Get Object NAME and ID commands to insert the username and password (i.e. the xxxxxxxxxx's) but when I right click to use "Inspect element" there is no name or id. It seems to be some sort of java script reference?
      I am using Windows 7 with latest updates and Internet Explorer version 11.
      As this is my first post I hope I am following protocols, and if not, please let me know and I will improve.
      Thanks

    • drorshem
      By drorshem
      Hi,
      I'm looking to create a script which will download all *.txt files from a remote FTP server.
      Once downloaded, delete all *.txt files.
       
      Can this be achieved using AutoIt ?
×