← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #156531]: Script clicks anywhere even if exists() fails

 

Question #156531 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/156531

    Status: Open => Answered

RaiMan proposed the following answer:
--1. looking for multiple images at the same time 
the faq 1568 especially in the section: 
**** a generalized, reusable version with exists() packed in a def() function
might be interesting for your situation, but has nothing to do with your problem.

--2. your situation
I take your workflow:
spoken the code should work this way:
if there is a picture = pic1 -> doubleclick otherwise ignore and continue with
if there is a picture = pic2 -> doubleclick otherwise ignore and continue with
-> if there are only pic 2-4 on the screen it should doubleclick just on these 3 pictures

from your code snippets above it is not clear, how your case selection works, therefor my version:
if exists(img1,0):
   # script here what has to be done if img1 exists, e.g.
   doubleClick(getLastMatch())
if exists(img2,0):
   # script here what has to be done if img2 exists, e.g.
   doubleClick(getLastMatch())
# add more of these blocks

--3. How to make your script robust:
- if possible restrict the searches to a region (e.g. reg.exists(img,0) and reg.getLastMatch())
- know the score values of your matches and arrange the workflow with descending Pattern(img).similar(value), so it should not happen, that something is found, that is not meant (you talk about similar looking images)

--4. How to develop this workflow
In this case, I would start without any actions, that are not needed to assure the workflow - e.g. very lean logging
print img1
if exists(img1,0):
   getLastMatch().highlight(2) # this prints a log message too
print img2
if exists(img2,0):
   print getLastMatch().highlight(2)
# more of these

So you get some knowledge about the matches( score values, found what
should have been found, ...)

--- One more thing:
It is always more guessing than knowing in situations like yours, since you would need the script, the images and some environmental screenshots to really analyze and make suggestions. So I hope this helps.
If not, feel free to come back. You might even send me some zipped stuff to my mail at 
https://launchpad.net/~raimund-hocke. I will have a look at it.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.