SikulixIDE 1.1.2 Click a random place inside an image

Asked by PowerPenguin on 2018-03-13

Hi! I'm new to Python (but not to coding) and there's something I'm trying to do but I'm not sure how to do it.

I want to click an image that appears in the screen several times (not one after other, after clicking it one time it disappears and appears again after a while), but I don't want to click it always in the center, I want to click it each time in a random place inside the image.

I've been messing with the Region class and the functions getTopLeft(), getBottonLeft() etc and the Random class of Python, I've changed my code a million times but I still can't figure it out. If you could help me it would be great. I've seen similar answers in the forum but I'm not sure how to implement them in my code.

This is what I have:

import random
m = find(imageIwantToClick)

And I get this error:
[error] Error caused by: Traceback (most recent call last): File "C:\Users\Penguin\Documents\Sikuli Pruebas.sikuli\Sikuli", line 3, in <module> l = random.randint(m.getTopLeft(),m.getBottomLeft()),random.randint(m.getTopRight(),m.getBottomRight()) File "C:\Users\Irene A\Desktop\Sikuli\sikulix.jar\Lib\", line 241, in randint TypeError: unsupported operand type(s) for +: 'org.sikuli.script.Location' and 'int'

From what I understand, I always have to introduce an image inside the function click() to make it work? But then, I don't know how to click in a place that isn't an image, just a coordinate in the screen.

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Manfred Hampl (m-hampl) said : #1



Best masuo (masuo-ohara) said : #2

Both getTopLeft() and getBottomRight() return Location object.
random.randint() require integer.


PowerPenguin (powerpenguin) said : #3

Thanks masuo, that solved my question.