← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #189093]: Loop doesnt work

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Without having a screenshot and knowing the captures, it is hard to
know, what your script does.

But I can say the following: 
If you do not specify a region, where you expect Sikuli to find something, that exists more than once on the screen, you will get the one you expect only by accident.
So this is exactly the case with your example.

It might be, that you think, that   m = getLastMatch().below()  does
something, but it only stores the region below the last match into the
variable m (which is not used further in the snippet).

You have 2 possibilities:

--1: use Pattern with target offset
b1 = Pattern("capture-of-the-whole-region-with-all-buttons.png").targetOffset(10, 20)
b2 = Pattern("capture-of-the-whole-region-with-all-buttons.png").targetOffset(10, 40)
b3 = .....

You can produce these line by line by copying the line and evaluating
the next target offset with Preview.

now you could do a loop like this:

for n in range(1,11):
     click(eval("b"+str(n)))
     wait(25) 
     # and more coding with each button

--2: use findAll()

btns = buttonRegion.findAll("button-image.png")

btns now contains all matches in arbitrary order, that where found in
buttonRegion.

You have to copy these matches into a list and sort it according to
there position.

now you can walk through the list:

for btn in sortedBtns:
    click(btn)
    # ...

for the specifics of findAll see docs.

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