WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with MSIE
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Accessing Download File Dialog Box


Question:

After completing a web form and creating a report, I'm trying to download a CSV file of the report. Since a Windows update a few months ago I cannot get Winbatch to access the buttons on the "Download File" dialog box. Can anybody help me download a file using Winbatch?

Answer:

I believe you will need two scripts to get the download to work. One is the main script, the other is called just before the CSV file is accessed. It is launched and basically waits for the download dialog to open, then punch the buttons and fill-in the filename and hit OK.

Here's the example I have. You'll have to alter the filename and may need to alter the dialog box name too.

#DefineFunction startMSIE(url)
   msie = ObjectCreate("InternetExplorer.Application")
   msie.addressbar = @FALSE
   msie.statusbar = @FALSE
   msie.menubar = @FALSE
   msie.toolbar = @FALSE
   msie.visible = @TRUE
   msie.navigate(url)
   WaitForMSIE(msie)
   Return(msie)
#EndFunction

#DefineFunction WaitForMSIE(msie)
   While msie.busy || msie.readystate <> 4
      TimeDelay(0.5)
   EndWhile
   Return
#EndFunction

#DefineSubRoutine BrowseButtonClicked()
   cf = "~Choose file"
   WinWaitExist(cf, 1)
   SendKeysTo(cf, fname)
   Return
#EndSubRoutine

url = "about:blank"
br  = startMSIE(url)

;;;;;;;;   make sure you change this to a filename that's within the current folder
;            your Choose file opens to...

fname = `"Binary Search.txt"` ;<-- must quote if you have spaces in file name...

br.document.writeln(`<input type="file" id="Name" size="50"/><br/><br/><input type="submit" id="MySubmit"/>`)

NameInput = br.document.all.Name

Run(StrCat(DirScript(), "SendKeys.wbt"), fname)  ;<-- can't use CALL must use RUN...
NameInput.click

Message("Debug", "The script can now continue...")

br.quit

Exit


Sendkeys.wbt

pwn = "~Choose file"
WinWaitExist(pwn, 10)
SendKeysTo(pwn, "%param1%{tab}{enter}")
Return
Exit

Article ID:   W17167
File Created: 2007:07:03:14:28:34
Last Updated: 2007:07:03:14:28:34