如何使用 VB 脚本处理 IE 下载对话框? [英] how to handle IE Download dialog with VB Script?

查看:29
本文介绍了如何使用 VB 脚本处理 IE 下载对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用VB Script自动将文件保存在特定位置?

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

或者如何在不交互的情况下将文件下载到 IE 中的特定位置带下载对话框?

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

最终我需要从 IE 自动将文件保存在特定位置.

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

谢谢.

推荐答案

我们使用 selenium 测试为文件对话框所做的是利用 AutoIt,一种免费的脚本工具,可创建与 Windows 组件对象模型交互的可执行文件——包括文件保存对话框.

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.

我要做的是制作一个简单的脚本,将文件保存在您想要的位置,编译为可执行文件,然后在 VBScript 中调用该程序.

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.

这是我们用于下载 Excel 文件的脚本,尽管它可能比您需要的要复杂一些.

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

这篇关于如何使用 VB 脚本处理 IE 下载对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆