Sign in to follow this  
Followers 0

Interact with "Save As" dialog

5 posts in this topic

#1 ·  Posted (edited)

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


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")
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)
;~ 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)
ControlSetText("Salva con nome","","[CLASS:Edit; INSTANCE:1]","")

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

It's based mostly on this post:

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

Share this post

Link to post
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.


Share this post

Link to post
Share on other sites

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

#4 ·  Posted (edited)

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
1 person likes this

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

#5 ·  Posted (edited)

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)

  ConsoleWrite(" --> Click save Button " & @CRLF)

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  
Followers 0

  • Similar Content

    • 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.

    • drorshem
      By drorshem
      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 ?
    • harvester2001
      By harvester2001
      Hi I need your help
      I need download backup from 200 remote pc. I calculate that I can download 20 backups in one time. I need to create loop, take localizations from txt file and start 20 downloads in one time (i want use ShellExecute and robocopy), after finish one from running 20 take another localizations from txt file until localizations finish. And I need trigger if is 7:00 pause script. I hope you know what I mean
      Many thanks for help, sorry for my english.
      This is what I got:
      #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <FileConstants.au3> #include <File.au3> #include <Array.au3> #include <Date.au3> Local $targets = @ScriptDir& "\targets.txt" Local $log_name = "\autoit.log" MsgBox($MB_SYSTEMMODAL, "", "start copy", 1) Example() Func Example() If Not FileExists($targets) Then MsgBox($MB_SYSTEMMODAL, "", "The file targets.txt - doesn't exist!") Exit EndIf FileOpen($targets, 0) Global $arr[1000] ReDim $arr[_FileCountLines($targets)+1] For $i = 1 to _FileCountLines($targets) $line = FileReadLine($targets, $i) $arr[$i] = $line ; Check if is online Local $iPing = Ping($arr[$i], 250) If $iPing Then ; ONLINE $rc = FileCopy("\\"&$arr[$i]&"\e$\backup\", @ScriptDir&"\downloads\"&$arr[$i]&"\", $FC_CREATEPATH) If $rc = 0 Then _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" ONLINE error") Else _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" ONLINE done") EndIf Else ;OFFLINE _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" OFFLINE") EndIf Next EndFunc ;==>Example MsgBox($MB_SYSTEMMODAL, "", "Finish downloads backups") Exit  
    • 31290
      By 31290
      Hi everyone, 
      Following this page:
      I have to download the BIOS for the E5440 model. As I don't know in which order Dell will place the description and the link to download the file (also because the 5440 can be put in first) I'd like to make  the following piece of code to search only first the link that deals with the E5440:
      (The only thing I'm sure is that the string E5440 will be either in the first or the second position and I need to download the corresponding link)
      Local $sRead = InetRead('', 1) ConsoleWrite(BinaryToString($sRead) & @CRLF) Local $aData = _StringBetween(BinaryToString($sRead), 'Type: BIOS', 'Category:') TrayTip("", "Downloading latest BIOS Version, please wait...", 10, 3) Local $aLinks = _StringBetween($aData[0], '<A HREF="/', '"><IMG') For $i = 0 To UBound($aLinks) - 1 $aLinks[$i] = '' & $aLinks[$i] Next Local $hDownload = InetGet($aLinks[0], @DesktopDir & "\BIOSE5450.exe", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) Do Sleep(250) Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD) Local $iFileSize = Round(FileGetSize(@DesktopDir & "\BIOSE5450.exe") / 1048576) InetClose($hDownload) MsgBox(0, "", "The latest E5450 BIOS (" & $iFileSize & " MB) have been downloaded")
      I was thinking of an string search in the array but all my attempts failed for now.
      Can someone could give me a hand over here.
    • 31290
      By 31290
      Hi Guys, 
      Hope you're doing fine today.
      Well, I'm trying to achieve something I want to integrate to a tool I already created.
      At work, we deploy computers massively and we use the tool to perform automatic operations. Then, we have to update the BIOS to the latest version. To avoid a heavy tool, I'd like to automatically download the latest BIOS on the Dell Website but the thing is that the name of the fail change when a new version is published. Of course, I cannot know what version will be deployed by Dell but I have this when connecting to the website:

      Thus, I don't know if the FOLDERXXXXX of the download URL will change if a new version ins deployed. 

      Here's one of the pages of a model we also use:
      Well, i'm kind of stuck here and maybe someone could point something out
      Thanks in advance