Search code examples
automated-testsrobotframeworkui-automationautoit

Clicking Windows Calculator buttons with AutoItLibrary for Robot Framework and RIDE


I have Robot Framework, RIDE and AutoItLibrary installed. I want to open an instance of Windows Calculator, click the 7 button, keep the window open for a couple of seconds, then close it.

The test case is running and passing, but the 7 button does not get clicked. Every step apart from clicking the button is being performed.

The strategy to click 7 is via coordinates. Using the AutoIt finder tool the coordinates of the 7 button were found. Unfortunately the finder tool does not show the name or ID of controls in the Calculator Window:

enter image description here

It appears that the coordinates are relative to the entire screen, not the Calculator window. So when an instance of this window is opened it may be at a different location. How can the button be reliably clicked?

Code:

*** Settings ***
Library           AutoItLibrary

*** Test Cases ***
TC0
    # Opens the Calculator, waits until it is active, keeps it open for 2 seconds, then closes it.
    Run    calc.exe
    Win Wait Active    Calculator
    ControlClick    Calculator    ${EMPTY}    ApplicationFrameInputSinkWindow1    left    1    50    350
    BuiltIn.Sleep    2s
    Win Close    Calculator

Solution

  • Run Scite.exe and paste this code:

    Run("calc.exe")
    WinWaitActive("Calculator")
    Send("7")
    sleep (2000)
    WinClose("Calculator")