Software Testing Material

A site for software testers. We provide free online tutorials on Manual Testing, Automation Testing - Selenium, QTP, LoadRunner, Testing Tools and many more.

  • Blog
  • Tutorials
    • Manual Testing
    • Java
    • Selenium
      • TestNG
      • Maven
      • Jenkins
    • Framework
    • Katalon
    • Agile
    • SQL
    • VBScript
    • API Testing
  • Tools
    • TestLodge
    • FrogLogic GUI Tool
    • CrossBrowserTesting
    • BrowserStack
    • TestCaseLab
    • Kobiton
    • PractiTest
    • Sikuli
    • Postman
  • Interview Q & A
    • Selenium
    • TestNG
    • Test Framework
    • Explain Framework
    • Manual Testing
    • Software QA
    • Agile
    • Testing As A Career
    • General Interview Questions
    • API Testing
    • SOAP
    • JIRA
    • Protractor
  • Free Resources
  • Guest Post
    • Guest Post Guidelines
  • Training

How To Scroll Web page using Actions Class In Selenium

Last Updated on March 23, 2017 by Rajkumar

To Scroll Web page using Actions Class in Selenium WebDriver:

Let’s see how to Scroll Web Page using Actions Class in this post. There are few ways to scroll Web page UP or DOWN. We are going to see those in this post in detail.

To achieve this we use Actions class in Selenium WebDriver.

Must Read: Actions Class in Selenium WebDriver

Use sendKeys() method and pass parameters as PAGE_UP or PAGE_DOWN to achieve our required goal.

Scenario to be automated

  1. Launch the web browser and open the application – “https://www.softwaretestingmaterial.com”
  2. Do scroll down
  3. Do scroll up
  4. Close the browser

Given clear explanation in the comments section with in the program itself. Please go through it to understand the flow.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package softwareTestingMaterial;
 
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
 
public class ActionsClass {
@Test
public void actionsClass() throws InterruptedException{
System.setProperty("webdriver.chrome.driver", "D:\\Selenium Environment\\Drivers\\chromedriver.exe");
                //creating an object 'driver'
WebDriver driver = new ChromeDriver();
                //Creating an object 'action'
Actions action = new Actions(driver);
                //open SoftwareTestingMaterial.com
driver.get("https://www.softwaretestingmaterial.com");
                //sleep for 3secs to load the page
Thread.sleep(3000);
                //SCROLL DOWN
action.sendKeys(Keys.PAGE_DOWN).build().perform();
Thread.sleep(3000);
                //SCROLL UP
action.sendKeys(Keys.PAGE_UP).build().perform();
                //driver.close();
        }
}

This can be achieved by using JavascriptExecutor too.

See this: Page Up and Page Down Using JavascriptExecutor

If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

SUBSCRIBE TO GET FREE EBOOK AND REGULAR UPDATES ON SOFTWARE TESTING

Filed Under: Selenium

data-matched-content-rows-num="2" data-matched-content-columns-num="3"
Previous Article:
Drag And Drop Using Actions Class In Selenium WebDriver
Next Article:
Mouse Hover Actions Using Actions Class In Selenium

About the Author

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

ADVERTISEMENT

Froglogic-Squish-GUI-Tester
CrossBrowserTesting

TUTORIALS

  • Manual Testing Tutorial
  • Selenium Tutorial
  • TestNG Tutorial
  • VBScript Tutorial
  • Agile Methodology
  • SQL Tutorial for Testers
  • INTERVIEW QUESTIONS

  • Framework Interview Questions
  • Real Time Manual Testing
  • 100 Top Selenium Interview Questions
  • 30 Top TestNG Interview Questions
  • Agile Interview Questions
  • 80 SQL Interview Questions
  • TESTING TOOLS

  • Test Lodge
  • FrogLogic Squish
  • Cross Browser Testing
  • BrowserStack
  • Test Case Lab
  • Sikuli
  • © 2019 www.softwaretestingmaterial.com | About us | Privacy Policy | Contact us | Guest Post | Disclaimer | Terms of use | Sitemap