How to scroll down the page through Selenium Web Driver

Page Scroll down script using selenium webdriver

package selenium_examples;


import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Sample {

public static void main(String[] args)
{

WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.co.in/preferences?hl=en#languages");
driver.findElement(By.linkText("Edit")).click();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(0, 300)");

 

}
}


Page Scroll up script using selenium webdriver

package selenium_examples;


import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Sample {

public static void main(String[] args)
{

WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.co.in/preferences?hl=en#languages");
driver.findElement(By.linkText("Edit")).click();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(300, 0)");
 

}
}



 



 

No comments:

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge