← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #185414]: observe inactive tab

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
myApp = App("title here")
myRegion = myApp.window()
if not myRegion:
    popup("didnt find it")
    exit(1)
myApp.focus()
myRegion.highlight(2) 
while 1:
    while not exists("X.png"):
        wait(30)
    click(getLastMatch()) 
    wait(5)

-- title here
must be the title of the browsers title bar, which should reflect the frontmost browser tab. Since Sikuli has no feature to bring a browser tab to front, you should decide to run your game in a separate browser window, so you can use app.focus().

Based on this recommendation I have changed your script like above.

Generally: Sikuli can only find (and click) what is currently visible on
the screen. So to not get any problems, you have to check, wether the
region, you want to act on (contains some button you want to click) is
visible. If you did not make your screen ready before starting your
script or any other actions, to make things visible (like using class
App), you will get find failed exceptions that usually stop the script.

Generally and especially while developing a script, endless looping does
not make sense, unless they contain some coding to end the loop under
specific conditions.

In your case, you might use instead of while 1:
for i in range(3):
which will run your loop 3 times and might be enough to test your approach.

While testing it is a good idea, to run the script in slow motion, which
makes it easier to see, what the mouse is doing.

--- does not make sense
    while not exists("X.png"):
        wait(30)
This waits until X gets visible. But if it gets visible shortly after the exists() did not succeed, it takes another 30 seconds until the script continues.
so this is better:
    while not exists("X.png", 0): wait(2)
This checks every 2 seconds only once (without the ,0 it will wait 3 seconds for X to get visible until it continues), so you have a delay of max 3 seconds (2 secs + search time).

Since you know the region, where your X should be, you should restrict
the search to that region, to speed things up.

So this would be my solution while testing.

myApp = App("title here")
myRegion = myApp.window()
if not myRegion:
    popup("didnt find it")
    exit(1)
myApp.focus()
myRegion.highlight(2) 
for i in range(3):
    while True:
        mX = myRegion.exists("X.png",0)
        if not mX: wait(2)
        else: break
    click(mX) 
    wait(5)

Have a look at http://sikuli.org/docx/region.html#exception-findfailed
There you can find an interactive version, to help to handle find failed situations during testing.

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