无法使用 Autoit 将文件保存在指定位置

Unable to save the file in specified location using Autoit

按照以下步骤将文件保存到所需位置:

第 1 步:另存为 window 打开(使用默认下载位置,文件名为 DOC)

第 2 步:输入文件名 "D:\temp\sample.pdf"(在编辑栏中输入)

第 3 步:点击保存按钮(点击按钮,文件下载到默认位置而不是 "D:\temp" 位置)

我用下面的 .au3 脚本创建了一个 .exe

WinWait("[CLASS:#32770]","",10)
Sleep(2000)
ControlSetText("Save As", "", "Edit1", $CmdLine[1])
Sleep(5000)
ControlClick("Save As", "", "Button1");
Sleep(5000)

点击保存后,它被保存在默认位置而不是指定位置。

下面的代码,执行脚本。

IO.popen('autoit_script.exe D:\temp') #Ruby Code

有办法解决吗?

这取决于您尝试自动化的软件,但通常发生这种情况是因为软件无法识别文件保存路径框中的更改。问题在于 ControlSetText 的工作方式。尝试使用 ControlSend 进行一些错误检查,以确保您尝试设置的文件路径正确。有时您必须尝试一些不同的变体,以了解哪些适用于您正在自动化的软件。您可以尝试以下两个示例:

示例一:

WinWait("[CLASS:#32770]", "", 10)

If Not @error Then ;make sure the window was found

     $hWin = WinGetHandle("[CLASS:#32770]") ;get window handle

     ControlSetText($hWin, "", "Edit1", $CmdLine[1]) ;set text
     ControlFocus($hWin, "", "Edit1") ;just to make sure we have focus
     ControlSend($hWin, "", "Edit1", "{ENTER}")) ;should work like click button 1 but you will have to check

    ;better then a sleep
    $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
    Do
    Until WinExists($hWin) = 0 Or TimerDiff($hTimer) >= 10000
EndIf

例子二:

WinWait("[CLASS:#32770]", "", 10)

If Not @error Then ;make sure the window was found

    $hWin = WinGetHandle("[CLASS:#32770]") ;get window handle

    While 1
        ControlSetText($hWin, "", "Edit1", "") ;just makes sure there is no text in the control text
        ControlFocus($hWin, "", "Edit1") ;just to make sure we have focus
        ControlSend($hWin, "", "Edit1", $CmdLine[1])) ;set text using ControlSend

        If ControlGetText($hWin, "", "Edit1") = $CmdLine[1] Then ExitLoop ;makes sure that the control got ALL of the text before exiting loop
    WEnd

    ControlClick($hWin, "", "Button1");

    ;better then a sleep
    $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
    Do
    Until WinExists($hWin) = 0 Or TimerDiff($hTimer) >= 10000
EndIf