Popup handling in sikuli

Asked by sriram

Hi all,

Is there a way to handle pop-ups in sikuli ( i don't want to create pop-up, I want to handle already existing pop-up) . Scenario is after submitting the form different pop-ups come for different errors. I want to handle pop-up something like this.
          If (popup exists with header)
                 get the body of the pop-up
                  click on control button(ok/cancel)

Thanks in advance

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

--- 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.

Revision history for this message
RaiMan (raimund-hocke) said :
#2

Uuuups, just realized a typo: a pair of brackets missing

    winPopup = Region(searchRegion.getLastMatch()).below(200)

Can you help with this problem?

Provide an answer of your own, or ask sriram for more information if necessary.

To post a message you must log in.