← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #284740]: How to stop loop when an image appears within a fixed region?

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Especially as a beginner, you should take a little time, to at least read across the docs, to know the basics about the features.
This will surely help, to understand snippets you just copy and paste from somewhere.

Furthermore I hope, you are using version 1.1.0

this is a more efficient version of your script:
# static definitions
Image1 = ("1453723117924-4.png")
Image2 = ("1453735625632.png")
stopRegion = Region(....) # see comment at the end
stopImage = "......png" # capture it here
# outer loop
while True:
    click(wait("1453202630435-1.png",30)) # only one search!
    # this is where i want to check for the image and quit if it appears
    if stopRegion.exists(stopImage, 0):
        break # leave the loop in case it exists
    #wait(80) # does not make sense, added to the next image wait
    wait("1453736008362.png",125),click("1453736008362-1.png") # see above, if you click the image, you are waiting for
    wait("1453202801705-1.png",25),click("1453202812250.png") # see above, if you click the image, you are waiting for
    #wait(10) # does not make sense, since you are waiting for images in the inner loop anyway
    # inner loop 
    while True:
        print('Searching....')
        # if/elif/else does not make sense here, because in case of true, you leave the loop anyways
        if exists("1453723117924-5.png", 0): # just one search only, if not there it wastes 3 seconds before the next exists is processed
            print("1453723117924-6.png") # does not make sense - use some understandable text
            click("1453723117924-7.png")
            # Break loop.
            break
        if exists("1453735625632-1.png", 0): # just one search only
            print("1453735625632-2.png") # does not make sense - use some understandable text
            click("1453735625632-3.png")
            # Break loop.
            break
    wait("1453202882292.png",25),click("1453202882292-1.png") # see above, if you click the image, you are waiting for

--- comment:
You either define the region where you check for the stopImage absolutely:
stopRegion = Region(x, y, w, h)
where you have to evaluate the coordinates somehow (e.g. with the region capture button).Region
This is suitable if the region is always in the same place.

If this is not the case, you have to find some image, that is always
there and then define stopRegion relative to it:

rel = find(fixedImage)
stopRegion = Region(rel.x + x1, rel.y + y1, w1, h1)

where you have to evaluate the x1, y1, w1, h1 with some tool or the
means of the IDE (e.g. Preview)

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.