Detect end of scroll

Asked by LaVonne Mangin

I have a Region defined that uses wheel to scroll down a table. Only ten rows of the table are visible at a time and the size of the table can change in between invocations of the program. Can you help me with detecting when the mouse has scrolled to the end of the table? I am also interested in how to get back to the top of the table. I haven't tried yet (because I can't stop at the bottom yet!), but I though I might be able to count the number of scrolls and simply tell wheel to scroll up the total number of scrolls all at once. If there is a more direct, succint way other than rescrolling could you describe it please?

Thank you very much,

La Vonne

Question information

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

--- find the end for scrolling
the easiest way is, to check after (or before) every scroll action, wether in the region at the bottom of the app area some footer image (something, below the table) gets visible.

--- scroll to top again
yes, the easiest method is to count the down-scrolls and then scroll back the same number of wheel steps.

another option is, to scroll to top as long as some top image gets visible again at the top of the app area.

Revision history for this message
LaVonne Mangin (lam29) said :
#2

Thank you Raiman. The problem is that only the table rows are scrolling, not the screen itself, so there are no changes to detect in the region. I was thinking maybe I could try to detect an image of the scrollbar when it's in the end-of-table position. Seems a little tricky because it is located on the opposite side of the screen, outside the scrolling region and there are other tables/scrollbars on the screen. Would have to find a way to make sure I find only the specific scrollbar associated with the scrolling table.

Appreciate the info!

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

ok, understood.

Then you should do it this way:

If the table cannot be scrolled anymore, the area shold not change its content after a scroll.

# capture a significant part of the table
tabPart = capture(some_region)

# make one scroll step

# check, wether things changed
if some_region.exists(tabPart):
     print "reached end of table"
     break # see continue
else:
     print "some more to scroll"
     continue # supposing we are in a loop

Revision history for this message
j (j-the-k) said :
#4

Just an addition because I had to solve this problem myself some days ago, I used the onChange observer:
The goal was to find an entry in the scrollable list.
It utilizes the fact that the appearance of the list will not change once the bottom or top is reached, because the scrolling stops there, but will change while scrolling is still possible.
The advantage of my script is that it does not need a bottom or top image of the list and automatically scrolls up and down. It probably isn't as fast as RaiMan's approach, I guess.

# direction of wheeling/scrolling
direction = WHEEL_DOWN

# flag to see if bottom of the list was reached
reachedBottom = False

# flag to see if top of the list was reached
reachedTop = False

# ist set True if the image was found
entryFound = False

# maximum number of scroll attempts, this may not be to small.
maxScrolls = 10

# the image that is searched in the list
goalImage = Pattern("xyz.png")

# global var to save all changeobserver results
changeResults = None

# start asynchronous observation
def startChangeObserve(region, time):
    global changeResults
    changeResults = []

    def changeHandler(result):
        changeResults.append(result)

    region.onChange(10,changeHandler)
    region.observe(time,background=True)

# I don't like loops that have any possibility to run endless, so I set a max. It is not needed normally, thnough.
for i in range(maxScrolls):
            if (listregion.wait(goalImage,0.3) == False): # no entry found
                # start searching for changes (asynchronous), see method below
                startChangeObserve(listregion, 0.5)
                # scroll down
                wheel(wheelLocation,direction,1)
                # wait for changelistener to complete
                wait(0.5)
                # check if any changes occurred
                if (len(changeresults) == 0): # no changes, scrolling did not change dropdown list, bottom or top reached.
                    if (direction == WHEEL_DOWN): # bottom reached, change wheel direction
                        reachedBottom = True
                        direction = WHEEL_UP
                    else: # top reached, change wheel direction
                        reachedTop = True
                        direction = WHEEL_DOWN
                    if (reachedTop == True and reachedBottom == True): # both ends of the dropdown-menu were reached, no more scrolling needed.
                        break
            else: # entry was found
                entryFound = True
                break

if (entryFound):
# do stuff if successfull

Maybe this can help someone sometime.

Can you help with this problem?

Provide an answer of your own, or ask LaVonne Mangin for more information if necessary.

To post a message you must log in.