scroll using java

Asked by Calle Rundgren

Maybe this should be in a java forum, but i will give it a try here.

I am scrolling a dropdown list using a java robot. In order to scroll until a certain object appears
I am using a while-loop.

while not exists(the object):
    from java.awt import Robot
    robot = Robot()
    robot.mouseWheel(100)

Using this code the wheel is just scrolling one step each loop. Is there a way to speed up the scrolling? There is about 200 objects in the dropdown list so it would be great if there was a faster way.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Calle Rundgren
Solved:
Last query:
Last reply:
Revision history for this message
Calle Rundgren (c-rundgren) said :
#1

Never mind, I will use type(Key.PAGE_DOWN) instead.

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

Sorry, to be late ;-)

using "not exists()" is a bit tricky:

since the "normal situation" is the "not found", every exists() takes 3 seconds ;-) the default waiting time!

In these situations, use exists(img, 0) which immediately returns after the first search trial.

So in your example with the dropdown list, you might restrict the search to the fixed region, where the entries traverse, when scrolling down or up (I recommend to use Sikuli's wheel() (http://sikuli.org/docx/region.html#Region.wheel))

so with something like this:

reg = Region( ... ) # the "looking glass"
steps = some-value # approriate value for stepped scrolldown
wheelPoint = reg.below(10).getCenter() # appropriate location to scroll
while not reg.exists("image-of-searched-item.png", 0):
     wheel(wheelPoint, WHEEL_DOWN, steps)

the thing should be speedy enough (a step should be about 0.2 seconds)