click( img ) not working..

Asked by Lawr Mcferran

Sikuli detects image and pretends clicking on it but is actualy just find & hover it, and after that going to the next function ...

[log] CLICK on (1313,126)

[log] CLICK on (496,477)

[log] CLICK on (1009,92)

[log] CLICK on (1413,231)

[log] CLICK on (403,558)

[log] CLICK on (1385,208)

[error] Stopped

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
Lawr Mcferran (ryid-king2) said :
#1

Sometimes it works but very rarely ....

Revision history for this message
j (j-the-k) said :
#2

I have never experienced something like this before, especially the "[error] Stopped" part.
Can you post the relevant part of your script and the details of your system you're running this on (operating system, java version, installed opencv version..)

Revision history for this message
Lawr Mcferran (ryid-king2) said :
#3

W7
java 6 update 31

[log] CLICK on (1385,208) here it doens't click

[error] Stopped here the program don't recognize the image on the screen , and the program will stop * this is not the problem*

i want ot click on [log] CLICK on (1385,208)

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

As j-the-k already told: there are some aspects, that might lead to "non"-clicks and so it is helpful, to have more information on the app you are trying to click on and some lines of code.

It might be a "having-focus-problem" or the app is not ready yet to accept a click at that point in that moment (timing problem).

In some cases it helps, to test the script in slow motion mode or just make some tests with a few lines of code to check the behavior of the GUI at that click point.

Revision history for this message
Lawr Mcferran (ryid-king2) said :
#5

it works if i change the click() function to this:

Region_Menu_Guide=find(Pattern("KuA4IITEErat.png").similar(0.83).targetOffset(-2,-22)) #Find this image anywhere on the screen
  Region_Menu=Region(Region_Menu_Guide).left(200) #Create a New region 200 pixel left of the finding image
  Region_Menu.setH(600) # setting New region height by 600
  Region_Menu.setW(600) # setting new region width by 600
  Region_Menu.click(Pattern("KuA4IITEErat.png").similar(0.83).targetOffset(-2,-22))

Revision history for this message
Lawr Mcferran (ryid-king2) said :
#6

so can u detect the problem ?

i allso have some questions like....

i have a circle and some difrent images...( A.B,C,.....n) at diffrent distances .i am in the middle, and i wanna click the nearest point (img)(A) at distance eg. 1 cm , and after take the B witch is at 2cm distance , after C,D.......

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

This is what you are doing:
Y - this is the region somewhere on the screen resulting from the first find (Region_Menu_Guide)
x - this is the region you are constructing based on Region_Menu_Guide

xxxxxxxxxxxxxxxxxxxxYYYYYYYYYxxxxxxxxxx
x Y Y x
x Y Y x
x Y YYYYYYYY x
x x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

So since this works at all (you say the click works),then already the first find was successful.
The only difference between
click(Pattern("KuA4IITEErat.png").similar(0.83).targetOffset(-2,-22))

and
Region_Menu_Guide=find(Pattern("KuA4IITEErat.png").similar(0.83).targetOffset(-2,-22))
Region_Menu=Region(Region_Menu_Guide).left(200)
Region_Menu.setH(600) # setting New region height by 600
Region_Menu.setW(600) # setting new region width by 600
Region_Menu.click(Pattern("KuA4IITEErat.png").similar(0.83).targetOffset(-2,-22))

that some more time elapses (somewhat between 0.5 and 1 second) after the first find and the final click().

So this should do the same:
wait(1)
click(Pattern("KuA4IITEErat.png").similar(0.83).targetOffset(-2,-22))

which only means, that you have to wait a little after the last action (seems to be a click too: question: [log] CLICK on (403,558) ) before trying to click again (this is what I meant with timing problems above).

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

--- i have a circle and some difrent images...
If you know the geometrics of your situation, then you could simply calculate the click points, may be by adding region creations like you used above around the reference point and looking for the images in that regions.

More detailed hints I could give after having looked at a screenshot somehow.

Revision history for this message
Lawr Mcferran (ryid-king2) said :
#9

I know the images. But they apear in a random mode...

(89,23) img B at moment +2 minutes
(23,45) img C at moment +6 minutes
(23,01) img D at moment +7 minutes
(22,01) img A at moment +7 minutes

So i have this... (sorry for my bad english)
 When an image apears on the screen i wanna click it.
 When is no image on screen.. wait untill a new one appears.
 When are more images in the same time, maybe the same type, i wanna click 1 and after the another.
                                                                          (if posible i wanna take the nearst one.. ).

Maybe u can help me... i know only C++ and i am starting to learn this too.

Revision history for this message
Lawr Mcferran (ryid-king2) said :
#10

Tnx for the click problem it works now. :D

Revision history for this message
Lawr Mcferran (ryid-king2) said :
#11

More easy if an image apears i wanna click on it...
(but if there are 2 or more same images ? can i take 1 ?)
if there is no image on screen sleep(..)
when image appear repeat process

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

--- first an example solution for your searching around an d click on nearest

(download a zipped .sikuli, so you might test it: https://dl.dropbox.com/u/42895525/circles.sikuli.zip )

# this should run on https://launchpad.net/sikuli

import math

# calculate the distance between 2 points
def calcDist(p1, p2):
    return int(math.sqrt(pow(p1.x-p2.x, 2) + pow(p1.y-p2.y, 2)))

# some images to search
imga = "1352554482821.png"
imgb = "1352554500021.png"
imgc = "1352554522969.png"
imgd = "1352554540352.png"
# put images in list
images = [imga, imgb, imgc, imgd]

# got to a reference point
ref = "1352554569162.png"
mRef = find(ref)
hover(mRef)
mRefCenter = mRef.getCenter()

# look for the images, highlight the found ones
matches = []
for img in images:
    matches.append(exists(img, 0))
    if matches[-1]:
        matches[-1].highlight()

# sort the matches by distance to ref point
matches.sort(key = lambda m : calcDist(m.getCenter(), mRefCenter))

# hover on every image, neareast first, switch off highlight
for m in matches:
    if m:
        hover(m)
        m.highlight()

wait(3) # give some time to watch ;-)

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

-- and now your question in comment #11

download: https://dl.dropbox.com/u/42895525/findall.sikuli.zip

# this should run on https://launchpad.net/sikuli

top = "1352556855570.png"

# define a search region
r = find(top).below()
r.highlight(2)

img = "1352556890908.png"
# get the most probable matches
matches = list((m for m in list(r.findAll(img)) if m.getScore()>0.95))

# sort top down (y value)
matches.sort(key = lambda m : m.y)

# show them
for m in matches:
    m.highlight(1)

Revision history for this message
Lawr Mcferran (ryid-king2) said :
#14

Thanks RaiMan, that solved my question.