Scrolling web page with Selenium Webdriver using java

We can scroll the web page using javaScript Executor in the java code.We have taken the below example with three different scenarios of scrolling a webpage.
  • 1. We may require to scroll to bottom of the page and then perform operations. For this scenario we have created a test 'scrollingToBottomofAPage'/
  • 2. Some times, we may require to scroll to particular element and peform operations on that particular element. For this we need to pass the element on which we need to perform operation. For this scenario we have created a test 'scrollingToElementofAPage'/
  • 3. We can also use the coordinates to scroll to particular position by passing the coordinates. For this scenario we have created a test 'scrollingByCoordinatesofAPage'/
  • The more better way to do this is having a utils class and define reusable methods. We can call these methods from different classes/tests.
  • We need to pass the driver to the method.
  • In the same way, we may need to scroll to particular element and perform operations. To do this we need the below example reusable method. We need to pass the driver and element.