Sign in to follow this  
Followers 0
MarcusL

IE10 - download Save As

4 posts in this topic

Hi all,

I have written the following script (with the help of others from this forum, thanks!). When I run through the script (tools->Go) it works. When I execute it from my VBA it works sometimes and not others. When it does not, it seems to not address the "save as" on the browser window but instead operates on the browser address bar instead.

I call the compiled script from my VBA once I have the browser display the "save as" window from my VBA. The script takes in a string for the download dir and file name to save.

RunScript = Shell("C:\My Code\download.exe C:\Test\data.csv")

I then execute this script (compiled)

;read arguments
$pathToSave=$CmdLine[1]


; get the handle of main window
Local $windHandle=WinGetHandle("[Class:IEFrame]", "")
Local $winTitle = "[HANDLE:" & $windHandle & "]"; 
;get coordinates of default HWND 
Local $ctlText=ControlGetPos ($winTitle, "", "[Class:DirectUIHWND;INSTANCE:1]")


; Select save as option
WinActivate ($winTitle, "")
Send("{F6}")
sleep(500)
Send("{TAB}")
sleep(500)
Send("{DOWN}")
sleep(500)
Send("a")


; Save as dialog
; wait for Save As window
WinWait("Save As")
; activate Save As window
WinActivate("Save As")
; path to save the file is passed as command line arugment
ControlFocus("Save As","","[CLASS:Edit;INSTANCE:1]")
Send($pathToSave,1)
sleep(500)
;click on save button
ControlClick("Save As","","[TEXT:&Save]")

Any ideas of what I am doing wrong pls. I need this step robust and reliable, but it seems more like lottery at the moment... also, is there a way of making it work regardless of focus on window? That is I have to leave PC unattended/untouched  for it to work (when it does!). Thanks

M

 

Share this post


Link to post
Share on other sites



Is there a download link on the page? If so you could just use InetGet to save the file rather than go through all that trouble. Try adding a small Sleep between commands if not to see if that helps your reliability.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi Wayfarer, thanks for the reply. 

There is no link for the files. All three sites I download from, require a button to be pressed, runs JS then the File Save As appears finally. I download 5 files total.

I have a  sleep 5000  (5 secs) in VBA once I click on the button, to allow the Save As to appear first (and I have tested this multiple times and the file save as always appears). But 3 out of six times, the script (AutoIt) works, the others it seems to target the browser address bar area. It is as if the window does not have focus or it starts with a different area of the page in focus (?!).

I would LOVE to work this with Chrome instead as I am starting to really dislike IE and the whole Save As process... With Chrome it just downloads to "Downloads" dir and that is it... Unfortunately Chrome is not so easy to navigate from VBA (I cannot seem to find much info on this on net).

So I am stuck with no link to download directly (I even tried HTTP approach with no luck as when you run mouse over the buttons you have a JS Script shown as what will execute, not a link to the file)/

Any suggestions on how to make the Save As bulletproof with AutoIt are appreciated!

M

Edited by MarcusL

Share this post


Link to post
Share on other sites

Wow, not having a lot of luck with this forum and this software. Shame, I like what is does. Anybody has any suggestions please? 

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