6

I'm attempting to automate an application using AutoIt, and I need to wait for a control to appear within the application before the automation can begin. This control loads shortly after the application starts, but it does not change the window title. How do I wait for the control to appear?

0

1 Answer 1

8

To get a handle to a control on another GUI you need to use the AutoIt Window Info Tool to identify that control. To get the classname of the control go to the tab "Control" and look up the value for "ClassnameNN". Now you can use this value as I did in the example below.

Of course you need to replace "Button1" with the information you got from the AutoIt Info Tool and modify the window titles accordingly.

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
2
  • 1
    @JohnMoses No the While (1) is correct since this is just a snippet and not a full working solution. AutoIt scripts that have an own UI consist of an infinite loop to catch the UI messages and this is what I wanted to show in my script. See: autoitscript.com/autoit3/docs/guiref/GUIRef_MessageLoopMode.htm
    – Andreas
    Commented Nov 21, 2016 at 6:31
  • @Richard: If you want to test if a control is currently being displayed on the GUI use GuiControlGetState as shown here.
    – Andreas
    Commented Dec 5, 2017 at 5:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.