Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoIt Wait for a Control Element to Appear

Tags:

autoit

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?

like image 761
JadziaMD Avatar asked Jan 28 '13 21:01

JadziaMD


1 Answers

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
like image 111
Andreas Avatar answered Sep 28 '22 08:09

Andreas