Make sikuli click a random link of a the ones that are found

Asked by Naus Town

I need sikuli to choose randomly from its image recognition findings, how is that possible?

My code in this case is:

 exists("autoSpectate.png",9999) # Wait for Spectate
 click("autoSpectate-1.png") # Click on Spectate

There are normally a few "Spectate"s, but it mostly clicks on the same one.

 Is there a possiblility to make it randomized intentionally?

Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1
Revision history for this message
obiwan-92 (obiwan-92) said :
#2

Hello,

To be a little more clear :
import random
l = []
for i in findAll("autoSpectate-1.png"): l.append(i)
click(random.choice(l))

Revision history for this message
Best RaiMan (raimund-hocke) said :
#3

ok, and a little bit more compact ;-)

import random
click(random.choice(list(findAll(("autoSpectate-1.png"))))

Revision history for this message
RaiMan (raimund-hocke) said :
#4

ok, once again:
click(random.choice(list(findAll("autoSpectate-1.png"))))

Revision history for this message
Naus Town (wertzugeld) said :
#6

Thanks y'all PROBLEM SOLVED!

Check different problem plz :) https://answers.launchpad.net/sikuli/+question/243270

Revision history for this message
Naus Town (wertzugeld) said :
#7

Thanks RaiMan, that solved my question.