Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 326
Mike Avatar asked Dec 04 '25 17:12

Mike


1 Answers

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.

like image 196
alecxe Avatar answered Dec 06 '25 06:12

alecxe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!