Search code examples
javatestingautomationautomated-testssikuli

How do I get a value from a particular location on screen using Sikuli(Java)?


My scenario:

Trying to automate Calculator using Sikuli(Java). I need to get the result (in text) every time an operation is completed. Example: 1 * 2 = 2. Need to capture '2' from the resulting area/region. Can some one please help me how can I do it?

The result may be dynamic, so It becomes important for me to read it in run time and then compare it with the input values.

Thank you, Mike


Solution

  • If the resulting area is a text field you can click on it, copy the text to the clipboard and read it from Env.getClipboard():

    click("text_field.png")
    type("a", KEY_CTRL)
    type("c", KEY_CTRL)
    print Env.getClipboard().strip()
    

    Another way is to find left and right borders of the result field, drag the mouse cursor from left border to the right, copy the text via ctrl+c and use Env.getClipboard() to get it.

    Hope that helps.