Finder class

Asked by Tiago Reis

Hi.

I have an array of images (communications) and in every images in the array I'm trying to find inside of that image another subimage ("E.png"). In some index positions there are images with the subimage "E.png" inside, but it returns everytime false.

 What I'm doing wrong?

My code is:

    communications = [("InterfaceAPI.png"),("Bridges8GPS.png"),
             ("InterfaceATC.png"),("ATCConfigura.png"),("ATCMessages.png"),
             ("InterfaceBHS.png"),("BHSSiemensMe.png"),("DownloadChut.png"),("Infrastructu.png"),("1350580843499.png"),("1350580851811.png"),("1350580861654.png"),
             ("InterfaceBIL.png"),("BillingMessa.png"),("BillingMessa-1.png"),
             ("1350570433841.png"),
             ("InterfacesPi.png"),
             ("1350570945044.png"),
             ("Ping8Bring.png")]
    for i in range(len(communications)):
        sleep(1)
        try:
            f = Finder(communications[i])
            if f.find("E.png"):
                 hover(communications[i])
            else:
                sleep(0.5)
                if exists(communications[i]):
                    keyDown(Key.CTRL)
                    click(communications[i])
                    keyUp()
            f.destroy()
        except:
            exit()

Thanks in advance,

Tiago Reis

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Tiago Reis
Solved:
Last query:
Last reply:

This question was reopened

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

correct usage of Finder class:

for i in range(len(communications)):
    sleep(1)
    f = Finder(communications[i]) # setup the Finder
    result = f.find("E.png") # search and return a Match Iterator
    if result.hasNext(): # check if we have one match
        hover(communications[i])
    else:
        sleep(0.5)
        if exists(communications[i]):
            keyDown(Key.CTRL)
            click(getLastMatch())
            keyUp()
    f.destroy()
exit()

Revision history for this message
Tiago Reis (tauflakes69) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
Tiago Reis (tauflakes69) said :
#3

Hi RaiMan.

It returns an error regarding with this

AttributeError: 'NoneType' object has no attribute 'hasNext'.

Sorry.

Revision history for this message
Tiago Reis (tauflakes69) said :
#4

Hi RaiMan.

I solved it.
    f = Finder(communications[i]) # setup the Finder
    f.find("E.png") # search and return a Match Iterator
    if f.hasNext(): # check if we have one match
        hover(communications[i])
    else:
     ...

Thanks :)

Revision history for this message
Tiago Reis (tauflakes69) said :
#5

Hi RaiMan.

I solved it.
    f = Finder(communications[i]) # setup the Finder
    f.find("E.png") # search and return a Match Iterator
    if f.hasNext(): # check if we have one match
        hover(communications[i])
    else:
     ...

Thanks :)