← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #181037]: Popup handling in sikuli

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
--- first question: how to detect a popup
check for an image of the invariant part of the popup window in a restricted region fixed (if popup always comes up in the same place on screen) or relative (if popup comes up relative to some other visuals of your app or the current mouse location)

--- second question: when to check for the existence of the popup
1. a fixed point in your workflow (seems to be your situation)
then you can use 
searchRegion = Region(where the popup is expected) # has to be evaluated/calculated somehow
if searchRegion.exists("popup-identify-image.png"):
    winPopup = Region(searchRegion.getLastMatch).below(200) # setting the popup body region somehow
    # evaluating the popup body to decide which button to click
    if isOK: winPopup.click("ok-button.png")
    else: winPopup.click("cancel-button.png")

2. popup in parallel to your workflow
use the observe() feature, e.g.

def popupHandler(e):
     print "popup detected"
     # more code like above to handle the popup

searchRegion.onAppear("popup-identify-image.png", popupHandler)
searchRegion.observe(FOREVER, background=True)

# now your normal workflow

You might need some logic to stop the observation if needed. The
observation runs in parallel, but when the handler works, your script is
paused until the handler returns.

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