Handling Page Scroll Down and Scroll Up

package testng;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class pageScroll {
	
	WebDriver driver;
	
	@Test
	public void scrollDrown() throws Throwable
	{
		driver = new FirefoxDriver();
		
		driver.manage().window().maximize();
		
		driver.get("http://www.facebook.com");
		
		Thread.sleep(5000);
		
		((JavascriptExecutor)driver).executeScript("scroll(0,600)");
		
		driver.quit();
	}
	@Test
	public void scrollUp() throws Throwable
	{
		driver = new FirefoxDriver();
		
		driver.manage().window().maximize();
		
		driver.get("http://www.facebook.com");
		
		Thread.sleep(5000);
		
		((JavascriptExecutor)driver).executeScript("scroll(0,600)");
		
		Thread.sleep(5000);
		
		Thread.sleep(5000);
		
		((JavascriptExecutor)driver).executeScript("scroll(0,-600)");
		
		Thread.sleep(5000);
		
		Thread.sleep(5000);
		
		driver.quit();
	}

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *