8

How to scroll down with Sikuli in Selenium Eebdriver with java?

I am using screen.wheel(1 , 8); in my code to scroll down in an open window.

Sometimes it works fine but after running my script 4-5 times it behaves differently. Instead of scrolling vertically it starts scrolling horizontally.

s.doubleClick("C:\\SikuliX\\Images\\C_Drive.png");
s.wheel( 1, 8); 
s.doubleClick("C:\\SikuliX\\Images\\DestinFolder.png");
s.doubleClick("C:\\SikuliX\\Images\\CfgFolder.png")

Please help and let me know how I can move the scrollbar vertically for specific steps and in particular window.

Eugene S
  • 6,709
  • 8
  • 57
  • 91
Jazz
  • 81
  • 1
  • 1
  • 4

4 Answers4

11

You can simply use shortcuts:

Windows Example:

type(Key.PAGE_DOWN) - scroll down 1 time
type(Key.PAGE_UP) - scroll up 1 time

Also if you want to repeat it a few times:

type(Key.PAGE_DOWN*3) - scroll down 3 times

MAC Example:

type(Key.DOWN, KeyModifier.CMD) - scroll all the way down

NOTE: If you really want to scroll down with the mouse wheel:

Mouse.wheel(WHEEL_UP, 1)
Mouse.wheel(WHEEL_DOWN, 2)
Assi.NET
  • 432
  • 4
  • 7
1

First of all, it has nothing to do with Sikuli. Second, keep in mind that the commands are being executed one by one and do not wait for the actual operation on the screen to complete. It is important to allow sufficient time for whatever it is you are trying to do to fully complete before calling the next command. By failing to do so, you are risking in ending up with a chaotic, inconsistent behavior. So just to find the culprit of you current issue, insert an explicit wait between all of your commands and also visually verify that each command is executed only after the previous one has completed. So you can insert something like this:

Thread.sleep(timeInMs);

Other thing to try scrolling using keyboard instead of the less reliable mouse scroll. You can do that like this:

s.type(Key.PAGE_DOWN);
Eugene S
  • 6,709
  • 8
  • 57
  • 91
0

Personally I like clicking the scrollbars Down Arrow in a For Loop until an image is found to indicate we've scrolled down far enough.

Ref: https://answers.launchpad.net/sikuli/+faq/1437

# --- this loops forever
while True:
   if not exists(img, 0):
      break # but ends if img gets visible
   else:
      pass # we will see
   wait(5) # check every 5 seconds
print img, "finally came up"

# --- this loops as long as img is visible
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • Hi, Jeremy. I think it will be better to have a mechanism with timeout in order not to loop forever if the image does not appear for some reason. – Assi.NET Dec 29 '19 at 07:43
0

Scroll down :

We need to pass "1"

Scroll up :

We need to pass "-1"

    public static void doAction(String action){
    switch (action){
        case "scroll-down":
            sc.wheel(Mouse.WHEEL_DOWN, 7);
            break;
        case "scroll-up":
            sc.wheel(Mouse.WHEEL_UP, 7);
            break;
    }
}

Sikuli lib screenshot for values : enter image description here

Jayanth Bala
  • 758
  • 1
  • 5
  • 11