【问题标题】:AutoIt Wait for a Control Element to AppearAutoIt 等待控制元素出现
【发布时间】:2013-01-12 08:38:35
【问题描述】:

我正在尝试使用 AutoIt 自动化应用程序,并且我需要等待控件出现在应用程序中,然后才能开始自动化。此控件在应用程序启动后不久加载,但不会更改窗口标题。如何等待控件出现?

【问题讨论】:

    标签: autoit


    【解决方案1】:

    要在另一个 GUI 上获取控件的句柄,您需要使用 AutoIt Window Info Tool 来识别该控件。要获取控件的类名,请转到“控件”选项卡并查找“类名NN”的值。现在你可以像我在下面的例子中那样使用这个值了。

    当然,您需要将"Button1" 替换为您从 AutoIt Info Tool 获得的信息,并相应地修改窗口标题。

    Global $hCtrl = 0, $Waiting = True
    
    ; your GUI loop
    While (1)
        If $Waiting And WinExists("Title of OtherApp.exe") Then
            $hCtrl = ControlGetHandle("Title of OtherApp.exe", "", "Button1")
            If $hCtrl Then
                ; we got the handle, so the button is there
                ; now do whatever you need to do
                GUICtrlCreateLabel("Button is there!", 10, 10)
                $Waiting = False
            EndIf
        EndIf
    
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    

    【讨论】:

    • @JohnMoses 不,While (1) 是正确的,因为这只是一个 sn-p,而不是一个完整的工作解决方案。拥有自己 UI 的 AutoIt 脚本包含一个无限循环来捕获 UI 消息,这就是我想在我的脚本中展示的内容。见:autoitscript.com/autoit3/docs/guiref/GUIRef_MessageLoopMode.htm
    • @Richard:如果您想测试一个控件当前是否显示在 GUI 上,请使用 GuiControlGetState,如 here 所示。
    猜你喜欢
    • 2016-05-09
    • 1970-01-01
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    相关资源
    最近更新 更多