0

how to save file automatically in particular location using VB Script ?

or How is it possible to Download file to particular location in IE without interacting with Download dialog ?

Ultimately I need to save file in particular location from IE automatically.

Thanks.

SmartSolution
  • 2,320
  • 5
  • 37
  • 49

2 Answers2

2

What we do for file dialogs with our selenium tests is to leverage AutoIt, a free scripting tool that creates executables that interact with the windows component object model--including file save dialogs.

What I would do is make a simple script that saves the file in your desired location, compile to an executable, and then in VBScript call that program.

Here is a script we use for downloading excel files, although it may be a bit more complicated than what you need.

WinWait("File Download", "", 60)
WinActivate("File Download")
IF WinActive("File Download") Then
    Sleep (500)
    SendKeepActive ("File Download")
    Send("!s")
    WinWait("Save As")
    WinActivate("Save As")
    Sleep (500)
    SendKeepActive ("Save As")
    If $CMDLine[0] > 0 Then
        Send($CMDLine[1])
    ELSE
        Send("C:\Windows\Temp\latestAutotestExport.xls")
    ENDIF
    Send("!s")
    Sleep (500)
    If WinActive("Save As") Then
        WinActivate("Save As")
        Sleep (500)
        SendKeepActive ("Save As")
        Send("!y")
        Sleep (15000)
    EndIf
    If WinActive("Download complete") Then
        WinClose("Download complete")
    EndIf
    WinClose("Blank Page - Windows Internet Explorer")
Else
    WinActivate("Microsoft Office Excel")
    IF WinActive("Microsoft Office Excel") Then
        Send("y")
    EndIf
    Sleep(500)
    Send("{F12}")
    If $CMDLine[0] > 0 Then
        Send($CMDLine[1])
    ELSE
        Send("C:\Windows\Temp\latestAutotestExport.xls")
    ENDIF
    Send("!s")
    Send("y")
    Send("!y")
    Send("!y")
    Sleep(5000)
    ProcessClose("EXCEL.EXE")
    Sleep(5000)
    WinClose("Blank Page - Windows Internet Explorer provided by Yahoo!")
EndIF
Aaron Silverman
  • 22,070
  • 21
  • 83
  • 103
  • thanks @zugwalt but, AutoIt is not working when RDP is closed. That is the reason we are looking for alternative solution. Or if you can suggest to make this script work on locked RDP. or some work around? – SmartSolution May 06 '11 at 06:06
  • AutoIt will need to be run on the actual machine with the browser, not over the network. – Aaron Silverman May 06 '11 at 15:08
-1

Forcing a file download in Internet Explorer is extremely bad practice. It's also a security risk. That's why there are no native methods for doing this. Can you provide a good reason for needing this? Otherwise, I'm not going to provide a solution for the reasons I've just stated.

Nilpo
  • 4,675
  • 1
  • 25
  • 39
  • It is for our internal testing/automation. We tried automating it using AutoIt it works when we are clicking on downloads,etc but when are connected to RDP and if we are closing the RDP my script hangs. – SmartSolution May 06 '11 at 06:07
  • 1
    The answer is not a solution, but rather a comment. For the first solution by @Zugwalt, there is a good workaround to the RDP problem, using Windows Auto Logon in Registry: http://serverfault.com/questions/269832/windows-server-2008-automatic-user-logon-on-power-on/606130#606130 – Noam Manos Jul 22 '14 at 15:17
  • Sadly my answer was deleted... Anyway, a straight forward solution would be to use a good **download manager add-on in Internet Explorer**. I was trying many kinds, but most did not work **with no user interaction**, so wasn't suitable for Automation task. Here's one freeware that did work: http://www.majorgeeks.com/files/details/dlexpert.html And if you encounter problems downloading files in HTTPS, or other authentication errors, try this freeware instead: http://www.orbitdownloader.com/download.htm – Noam Manos Jul 23 '14 at 14:20