Not find exception thrown unexpectedly

Asked by matteoa

Hello,
I'm using 1.1.4-SNAPSHOT-#221-2019-03-05_11:49/Windows10.0/Java8(64)1.8.0_191-b12
I have to click on a button, that will cause the visible page to change making appearing FirstElementOfNewPage.png, from then the script goes on.
Sometimes (~2% of cases) the target application doesn't reacts to the first click (Settings.MoveMouseDelay=0.1) and so the FirstElementOfNewPage.png doesn't appears, my idea would be in these cases to reclick on the same button and retry the search for FirstElementOfNewPage.png.

I have a script like this one:
    try:
        click("ChangePageButton.png")#first try
        mouseMove(100, 100) #this is present to move the mouse cursor from the button and allow a better finding of the button for second try
        wait ("FirstElementOfNewPage.png",30)
    except:
        click("ChangePageButton.png")#retry
        wait ("FirstElementOfNewPage.png",30)

What happens is that the script goes in the except part 80-90% of the times, also when the situation is completely ok (i.e. FirstElementOfNewPage.png is well visible). Prior that introducing the try-except the script was working rather well with a notFound problem every ~50 attempts.
I was wondering if the wait (or MouseMove) operation could trigger somehowthe exception.
Thanks for help!

Question information

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

click("ChangePageButton.png")
button = getLastMatch()
if not exists("FirstElementOfNewPage.png",30): # must this really be 30 seconds????
        click(button) # will click the match from the first click, no additional search
        if not exists("FirstElementOfNewPage.png",30):
            pass # here you might do some error actions

--- mouseMove(100, 100) #this is present to move the mouse cursor from the button and allow a better finding of the button for second try
generally not necessary: the mouse cursor is not visible on the internal screenshot used for image search

Revision history for this message
matteoa (matteoa) said :
#2

hello,
thanks for support, I put your code on operation and it works.
About the MouseMove we found that, possibly because we are using a VNC app to mirror the screen of the application we want to automate, the cursor is visible in the screenshot.
Thanks a lot!

Revision history for this message
matteoa (matteoa) said :
#3

Thanks RaiMan, that solved my question.

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

Thanks for the clarification about the VNC app and the mouse cursor in the shot.