Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

vbscript - how to handle IE Download dialog with VB Script?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:WindowsTemplatestAutotestExport.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:WindowsTemplatestAutotestExport.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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...