make every click random on a picture

Asked by Ben Dix on 2020-11-21

Hi,
new to Sikuli, but love it 😄

Is there a way to change the "click" command or add another command, so that the click action for every picture will be done different on the picture itself?

something like:
clickRandom(picture)
clicks somewhere in the picture area...not a specific point...

I already did this trick:

m = find("alliance.png")
click(Location(random.randint(m.getX(),m.getX()+m.getW()),random.randint(m.getY(),m.getY()+m.getH())))

but it would be much easier to define the "random" action in general, to shorten the text...

any ideas?

thx

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2020-11-21
Last reply:
2020-11-25

This question was reopened

TestMechanic (ndinev) said : #1

1. Define function

def RandomClick(element):
    m = find(element)
    click(Location(random.randint(m.getX(),m.getX()+m.getW()),random.randint(m.getY(),m.getY()+m.getH())))

2. Then you can use this function in your code

RandomClick("some_picture.png")

Ben Dix (bendix80) said : #2

yeah!
thx a lot!
will try this!

Can you help with this problem?

Provide an answer of your own, or ask Ben Dix for more information if necessary.

To post a message you must log in.