inconsistent error handling if findAll() loop

Asked by Phil McCready on 2017-03-10

In this code I am trying to use the if findAll() statement to respond when a search request generates a "This report cannot be completed" popup message.

The if findAll(): locates an image (bold type "Information" header) and seeks to click an "Ok" button then resets search parameters to start a new search.
The else: condition continues with a normal download and saves the request files in .xlsx and .pdf format.

Almost identical code versions are generating different and incorrect outcomes. Version 1 code was created in Sikuli 1.1.1, and it correctly handles the "This report cannot be completed" error condition BUT fails to handle a normal save condition.

Version 2 (created in Sikuli 1.1.0) correctly handles the else: normal download (else:), but fails on the if findAll() condition when this appears ("This report cannot be completed" popup). I have tried creating images in all the different tools, saving images in various locations and pasting in code as plain text to eliminate the impact of any version differences. No error statements are showing in either version 1 or 2, e.g. image file not found?

I am a rookie Python coder, so will not be shocked if found to be missing something obvious.

VERSION 1

click(Location(-801, 92))
wait(2)
type("44.07")
wait(1)
click(Location(-525, 361))
type(Key.ENTER)
wait(10)
r = Region(-937,209,142,50)
if findAll("Report-cannot-be-completed-v2.png"):
    click(Location(-384, 347))
    wait(2)
    click(Location(-327, -14))
    click(Location(-135, 31))
    click(Location(-432, 92))
else:
    click(Location(-159, -13))
    click(Location(-162, 39))
    wait(2)
    type(Key.BACKSPACE)
    wait(1)
    type("44.07_Social Work")
    click(Location(-280, 439)) # Save file

() loops back to start a new search with the next set of parameters

VERSION 2

click(Location(-801, 92))
wait(2)
type("44.07")
wait(1)
click(Location(-525, 361))
type(Key.ENTER)
wait(10)
r = Region(-937,209,142,50)
if findAll("Report-cannot-be-completed-v2.png"):
    click(Location(-384, 347))
    wait(2)
    click(Location(-327, -14))
    click(Location(-135, 31))
    click(Location(-432, 92))
else:
    click(Location(-159, -13))
    click(Location(-162, 39))
    wait(2)
    type(Key.BACKSPACE)
    wait(1)
    type("44.07_Social Work")
    click(Location(-280, 439)) # Save file

() loops back to start a new search with the next set of parameters

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2017-03-13
Last reply:
2017-03-14
RaiMan (raimund-hocke) said : #1

--1: I strongly recommend, to only use version 1.1.1, especially as newbee.

so I only speak for 1.1.1

--2: findAll in all cases returns a list object (which might be empty), so

if findAll()

will never be false.

see the doced examples:
http://sikulix-2014.readthedocs.io/en/latest/region.html#Region.findAll
http://sikulix-2014.readthedocs.io/en/latest/match.html#iterating-over-matches-after-findall

Phil McCready (pmccready) said : #2

RaiMan > 1: I strongly recommend, to only use version 1.1.1, especially as newbee.

> Yes, I am using this solution.

RaiMan > 2: findAll in all cases returns a list object (which might be empty), so ‘if findAll()’ will never be false.

> I substituted 'if findAll()' with 'if exists()'

Further testing revealed that the cause of the problem is that Sikuli is unable to read text or recognize images from this website that uses flash/javascript.

        The web page text looks normal 80% gray … it can be selected, copied and pasted in the usual way.

Identical text or cropped images of target text displayed in a word document are recognized by Sikuli, and the code works fine.

           Is there a workaround to have 'if exists()' work on a website using flash/javascript?

RaiMan (raimund-hocke) said : #3

Without having a chance to see the original images and webpage: no chance to comment.

you might send me something to look at to sikulix--at--outlook--dot--com

Can you help with this problem?

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

To post a message you must log in.