scroll down until image is seen on screen

Asked by Marc Summers on 2018-04-17

There is a specific image that I need to find
but the distance to scroll to it changes every two weeks.
But the horizontal spacing is the same, at 7 wheel downs.
So what I want to do is have findAll look for the image
and if it does not find anything then scroll down
7 more. Keep doing this scroll down 7 until it
finds the image.
So what am I doing wrong here ?

while(1):
    try:
        icons = findAll("1523914836809.png")
        if exists(icons):
            break
        else:
            wheel(Location(661, 465),WHEEL_DOWN,7)
    except Exception:
        pass

[error] script [ 796_795_garmin_charts_ctrl_eu_ifr_tdd_nd ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last): File "C:\Users\marc.summers\Desktop.sikuli\796_795_garmin_charts_ctrl_eu_ifr_tdd_nd.sikuli\796_795_garmin_charts_ctrl_eu_ifr_tdd_nd.py", line 12, in <module> icons = findAll("1523914836809.png") File "C:\Users\marc.summers\Desktop.sikuli\796_795_garmin_charts_ctrl_eu_ifr_tdd_nd.sikuli\796_795_garmin_charts_ctrl_eu_ifr_tdd_nd.py", line 12, in <module> icons = findAll("1523914836809.png") Line 2469, in file Region.java
at org.sikuli.script.Region.findAll(Region.java:2469)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
org.sikuli.script.FindFailed: FindFailed: 1523914836809.png: (209x19) in S(0)[0,0 1920x1200] E:Y, T:3.0 Line 2469, in

file Region.java

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Marc Summers
Solved:
2018-04-18
Last query:
2018-04-18
Last reply:
Marc Summers (2aircraft) said : #1

sikuli 1.1.2

java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

OS Version: 10.0.15063 N/A Build 1506

Maze (msx-n) said : #2

not sure if this will help you but it sounds like a similar task:
https://answers.launchpad.net/sikuli/+question/235440

Marc Summers (2aircraft) said : #3

They said it could not be done,
this is how it is done:

found = 0
while(found == 0):
    try:
        for i in findAll("1524078692187.png"):
            hover(i)
            if find("1524078692187.png"):
                found = 1
                break
    except FindFailed:
        wheel(Location(600, 450),WHEEL_DOWN,7)

RaiMan (raimund-hocke) said : #4

not sure, who told you "it could not be done"

Your solution is a bit overkill and if the image is not found, it will loop forever.

this works in all cases and is fast.

max = 10 # how often to scroll max
while max > 0:
    if not exists("1524078692187.png", 0):
        wheel(WHEEL_DOWN,7)
        max -= 1
    else:
        max = -1 # to show it is there
        break
if max > -1:
    print "image not on page"
    exit(1)
# image was found, we can proceed
found = getLastMatch() # here is the image

Marc Summers (2aircraft) said : #5

Hello RaiMan:

Thanks so much for your help. :)
It is much appreciated.

SikuliX "RULES!" :)