Search code examples
autoitwindows

Verify for text on windows application from AutoIT


I have a automating a Windows application using AutoIT tool. I have done the scripting now I need a command by which I can verify that the particular text on the application?

For eg: I open the application, then I execute the some task. Once task is compelete success is displayed on the application screen. I want to verify wheather success was displayed when task was completed.

Let me know how this can be done through AutoIT


Solution

  • that depends alot how the application is designed. with autoit for most windows-based uis, you can use the autoit window info tool to inspect elements, then with that info, get the control's text or value with

    controlGetText [1]

    #include <MsgBoxConstants.au3>
    
    Example()
    
    Func Example()
        ; Run Notepad
        Run("notepad.exe")
    
        ; Wait 10 seconds for the Notepad window to appear.
        Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)
    
        ; Set the edit control in Notepad with some text. The handle returned by WinWait is used for the "title" parameter of ControlSetText.
        ControlSetText($hWnd, "", "Edit1", "This is some text")
    
        ; Retrieve the text of the edit control in Notepad. The handle returned by WinWait is used for the "title" parameter of ControlGetText.
        Local $sText = ControlGetText($hWnd, "", "Edit1")
    
        ; Display the text of the edit control.
        MsgBox($MB_SYSTEMMODAL, "", "The text in Edit1 is: " & $sText)
    
        ; Close the Notepad window using the handle returned by WinWait.
        WinClose($hWnd)
    EndFunc   ;==>Example
    

    Start with that and let me know if you need more help!

    [1] https://www.autoitscript.com/autoit3/docs/functions/ControlGetText.htm