【问题标题】:Autoit and notepadAutoit 和记事本
【发布时间】:2014-03-17 17:29:45
【问题描述】:

我有一个应用程序,其中有一个“另存为”对话框。有时,如果存在同名文件,则会出现另一个对话框,同名“另存为”。以下是我编写的代码,但它没有按预期工作。

Global $sTitle = "Save As"

WinWait($sTitle)
WinWaitActive($sTitle)

ControlClick($sTitle, "Save", "[CLASS:Button; TEXT:&Save; INSTANCE:2]")
ControlSetText($sTitle, "", "CLASS:Button; INSTANCE:2]", $file_name)

SendKeepActive($sTitle)
Send("{ENTER}")
Sleep(4000)
WinWaitActive($sTitle,"",3)

If WinExists($sTitle, "No") Then Send("{ENTER}")
If WinExists("Exit OmniPeek") Then
    Send("{ENTER}")
Else
    Sleep(2000)
    WinClose($closing_file)
EndIf

这个想法是检查第二个“另存为”对话框是否出现,如果确实出现,然后覆盖现有文件。但是,这似乎不适用于我编写的 autoit 脚本。

有人可以帮我写这个脚本吗?您也可以使用记事本重新创建问题。只要有一个名为 abc.txt 的文件并尝试保存一个同名的文件 您将看到另一个名为“另存为”的对话框。

【问题讨论】:

    标签: automation automated-tests autoit


    【解决方案1】:

    试试这个:

    Example()
    
    Func Example()
        ; Run Notepad
        Run("notepad.exe")
    
        ; Wait 10 seconds for the Notepad window to appear.
        Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)
    
        ; Keep the Notepad window active when using the Send function.
        SendKeepActive("[CLASS:Notepad]")
    
        ; Simulate entering a string of text. If you try to change to a different window other than Notepad, then the Notepad window will
        ; be brought to focus again.
        For $i = 1 To 10
            Sleep(5)
            Send("notepad - ")
        Next
    
        ; Disable the Notepad window being active when using the Send function.
        SendKeepActive("")
    
        ; Close the Notepad window using the handle returned by WinWait.
        WinClose($hWnd)
    
        Send("{ENTER}") ; <<< SAVE
    
        ; Now a screen will pop up and ask to save the changes, the classname of the window is called
        ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
        WinWaitActive("[CLASS:#32770]", '', 2)
        Sleep(50)
        Send('newName.txt')
        Sleep(1000)
        Send("{TAB}{ENTER}")
    EndFunc   ;==>Example
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-20
      • 2013-03-08
      相关资源
      最近更新 更多