Problem if Exists(Image)

Asked by Marc

Hi again, I've some trouble with this :

def Search():
    if exists(image):
        for x in findAll(image):
            click(x)

[error] FindFailed ( can not find P(xxxxxx.png)

I've understood that if there are no images to find, it fails, but how can I do then ?

(I want to click on all images corresponding but if there are no images, don't do anything at all and continue my script)

Thanks again, quick and precise :)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
masuo
Solved:
Last query:
Last reply:
Revision history for this message
masuo (masuo-ohara) said :
#1

setFindFailedResponse(SKIP) may be useful in this case.
Make sure it meets the purpose.
See document.

http://sikulix-2014.readthedocs.io/en/latest/region.html?highlight=setFindFailedResponse#Region.setFindFailedResponse

Revision history for this message
Marc (marcothedwarf) said :
#2

Ok so I used :

setFindFailedResponse(SKIP)

def Search():
    if exists(image):
        for x in findAll(image):
            click(x)

I get :
[error] TypeError ( 'NoneType' object is not iterable )
[error] --- Traceback --- error source first line: module ( function ) statement 55: main ( search ) for x in findAll(image):

And in another fonction I have just :
def Check_Cbt():
    if exists(OK):
        click(OK)

ONLY this, BUT I get :
[error] FindFailed ( can not find P(OK.png) S: 0.71 in R[0,0 1920x1080]@S(0) )

Why....?

Revision history for this message
Best masuo (masuo-ohara) said :
#3

[example:]
setFindFailedResponse(SKIP)

findAll("image.png")
mm = SCREEN.getLastMatches()
if mm is not None:
    while mm.hasNext():
        click(mm.next())

setFindFailedResponse(ABORT)

http://sikulix-2014.readthedocs.io/en/latest/match.html?highlight=findAll

Revision history for this message
Marc (marcothedwarf) said :
#4

Thanks masuo, that solved my question.