1

I have a div element that I want to scroll down inside it with selenium. I want to scroll specific pixels.
What is the easiest way to do it?
I searched on web but didn't find fine explanation.

Prophet
  • 32,350
  • 22
  • 54
  • 79

1 Answers1

1

You can use this method:

public void scrollOnElement(String cssSelector){
    JavascriptExecutor js = (JavascriptExecutor)driver;
    String script = String.format("document.querySelector('%s').scrollTop= 450",cssSelector);
    js.executeScript(script);
}

The css parameter here is the css selector locating the div element you want to scroll inside.
I use 450 pixels scrolling here however you can use any parameter instead.

Prophet
  • 32,350
  • 22
  • 54
  • 79