Detect a dialog box

Asked by tlondon

Problem: Often times I'm unable to detect images using the wait() or exists() methods. This seems like a really easy problem but I'm consistently having an issue with this. It's different things I'm trying to detect but most often it's a Windows dialog box with text. I've tried a couple solutions (exists and wait, neither yields a greater chance of success):

Solution 1
if exists(image.jpg):
      print 'I like cookies'

Solution 2
p = Pattern("image.jpg")
p.similar(.85)
if exists(p):
      print 'I like cookies'

These solutions sometimes work but often they don't. I'm not sure why. I've tried taking extremely small images of the dialog box, even just a word from the box. There are no strange backgrounds or colors. It's just black text on a gray background. I've also tried taking screenshots of other things (a PDF) without much success.

Thank you so much for your help.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
tlondon
Solved:
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

Just a guess..
Since this is a very basic Sikuli functionality, I find it hard to believe that there is any core issue with image detection.
What I would check is timing settings. Could it be that you try to detect the image before it actually appeared on the screen? This is in case it takes some time for your Dialog Box to appear.
Try to add something like that before your "if exists(image.jpg)" statement:

time.sleep(2)

Don't forget to import the "time" module:

import time

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

@Eugene
--1. I do not think, that this is a timing problem, since in the standard the find operation already waits for 3 seconds.

--2. Sikuli has a wait(seconds) function. no need to use time.sleep().
... and time is already imported by Sikuli, no need to import again. same goes for sys.

@tlondon
It is hard to guess, what is happening there.
If it is ok for you, send some screenshots and images you use in exists(image) all zipped together silently to my mail at https://launchpad.net/~raimund-hocke

Revision history for this message
tlondon (telconstar99) said :
#3

Thank you for the responses folks.

When preparing my images for RaiMan, I wanted to double check and make sure that larger images failed also. I did this so I could send my small images and larger images and say "Both of these failed". As it turns out, the larger images worked without issue. I'm guessing my images were just too small - they captured only a part of a word (they weren't even the full height of a letter). As soon as I made them bigger it worked like a champ. Maybe that was my only problem? I'm not sure but for now I'm not experiencing this problem anymore.