← Back to team overview

sikuli-driver team mailing list archive

[Bug 1078806] Re: not exists doesn't do anything

 

Using "not exists()" in this form (searching the whole screen) is always
risky, since you might get false positives, that look like the exists()
is not working.

To make this robust, you need a shot, that gets a score (when found) of 0.95 and more.
Next you should restrict the search region to an area as small as possible, so you get something like this:

m = reg.exists(Pattern("HEWLETTPACKA.png").similar(0.95))
if m: reg.getLastMatch().highlight(2); exit()

run this until the region reg and the image are optimized.

reg can be evaluated relative to something else, that can be found with
a score of >0.95.

one more thing:
It seems, that you are using 2 different shots for the same visual content (HEWLETTPACKA and HEWLETTPACKA-1), this should be avoided in any case:
img = Pattern("HEWLETTPACKA.png").similar(0.95) # the optimized shot see above

and then
if not reg.exists(img):

and later
if reg.exists(img): break

and finally
doubleClick(reg.getLastMatch()) # use what already was found before

BTW:
"breakpoints" especially on windows can easily be implemented using input().

-- 
You received this bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/1078806

Title:
  not exists doesn't do anything

Status in Sikuli:
  New

Bug description:
  I am using a patched version of Sikuli X 1.0rc Maltipoo on 32-bit
  Windows XP.

  Here is the offending code:

  i = 0
  if(not exists("HEWLETTPACKA.png")):
      click("1352827765773.png")
      while (i < 10):
          type(Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN 
               + Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN 
               + Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN 
               + Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN 
               + Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN 
               + Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN + Key.DOWN)
          if(exists("HEWLETTPACKA-1.png")):
              break
          i = i + 1

  doubleClick("HEWLETTPACKA-1.png")

  Basically, I'm trying to check for the existence of an HP order in a
  list of orders that need to be filled.  If it doesn't exist, click the
  beginning of the list and scroll down until a new page of orders is on
  the screen and search again. If it appears on the screen, break out
  and double click the order to open it.

  For some reason when the script is running the if not
  exists("HEWLETTPACKA.png")): is either evaluating to it's opposite or
  not being evaluated at all. But then when I get to the double click it
  can't find the HP order because it doesn't exist! The exact same code
  was working just fine yesterday, which is really weird.

  I looked at the matching preview and fiddled with similarity but that
  didn't help. The preview says it's finding the matches it should be
  finding. I also tried saving the value returned from exists outside of
  the if statement and comparing it to None but that didn't work either.

  I do notice that when I comment the line out, the HP image and
  following parenthesis and colon aren't greyed out. I tried retyping
  the line and taking a new screenshot but it didn't help the commenting
  or the failing code.

  I put it in a try: Except FindFailed: statement and it seems that when
  I try to find "HEWLETTPACKA.png" it doesn't actually throw an
  exception or go into the code within the except statement. However,
  when I try to doubleClick the image after the except code block, it
  does throw the exception. When I run the code block from the except
  statement by itself it works great and scrolls until it finds an HP
  order with no issues.

  Here's the offending try/except code:

  i = 0
  try:
      find("HEWLETTPACKA.png")
  except FindFailed:
      click("1352827765773.png")
          #... same as before...

  doubleClick("HEWLETTPACKA-1.png")

  Breakpoints in the sikuli IDE would make my life, guys. :) I have no
  idea what's going on here.

To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/1078806/+subscriptions


References