← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #205813]: Detect end of scroll

 

Question #205813 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/205813

j posted a new comment:
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.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.