← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #200765]: new to sikuli need help please

 

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

RaiMan proposed the following answer:
Here you are again ;-)

before looping around, you should try to get your main issue resolved:
tracking the icon.

You could use onChange/observe, but my experience is, that only in
asynchronous situations (observe in background, while the main script
keeps running), the additional effort to get it running pays back.

So for inline waits (synchronous), in my opinion, using exists(image, 0)
(searches only once) is the most flexible and efficient way.

example: (only the icon workflow once)

icon_start = "image of the original icon"
# this should have as little background as possible

myreg = "a region, where we expect the icon to appear, as small as
possible"

type("mykey") # this triggers random appearance of icon

# first we wait for the icon, to get its region on the screen
mIcon = wait(icon_start, 20) # its an error, if it does not appear after e.g. 20 secs, script should stop then
mIcon.highlight(1) # to show, where we found it (debug only)

# now we look for the icon to change
# we look in the region of the icon with the start icon image
while mIcon.exists(Pattern(icon_start).similar(0.99)), 0):
    pass # search continuously
    # or wait(1) to search once per second

# this loop will end, if it is sure, that the icon will change at some time
# an alternative with a max wait time, see below

# now we can click
rightClick(mIcon.getCenter().offset(11,9))

--- comment on setThrowException(False)
I do not recommend this. If you want a find operation to be processed anyway, use exists()
Then you can use find and wait in situations, where the visuals should be found normally, but not found is exceptional and should terminate the script, because it would not make any sense to proceed.

e.g.

click("image") # would error if not found
click(exists("image")) # would do nothing if not found

--- an alternative with a max wait time

max = 50 # seconds
found = False
start = time.time()
while mIcon.exists(Pattern(icon_start).similar(0.99)), 0):
    wait(1) # to search once per second
    if time.time()-start > max: break
else:
   found = True

if not found: print "we should stop here"; exit()
# normal workflow proceeds

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