public class Scrollingonpage { public WebDriver driver; @Test (priority=1)// Scroll down public void ScrollDown() throws Exception { driver.get("http://selenium4learning.blogspot.in/"); driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("scroll(0, 900)"); // Y value is scroll down Thread.sleep(5000); } @Test (priority=2)// Scroll up public void ScrollUP() throws Exception { driver.get("http://selenium4learning.blogspot.in/"); driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("scroll(900, 0)"); // Y value is scroll down } @Test (priority=3)//Infinite Scroll Down public void InfiniteScrillDown() throws Exception { driver.get("http://selenium4learning.blogspot.in/"); driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS); { Thread.sleep(1000); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));"); } } @Test (priority=4)// Infinite Scroll public void InfiniteScroll() throws Exception { driver.get("http://selenium4learning.blogspot.in/"); driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS); Actions act = new Actions(driver); for(int i=0;i<=25;i++) { Thread.sleep(1000); //driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS); act.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform(); // Shourtcut key for Infinite scroll (Ctrl+End) } } @Test (priority=5)// Continious Scrolling public void ContiniousScrolling() throws Exception { driver.get("http://selenium4learning.blogspot.in/"); driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS); { for(int i=0;i<25;i++) { //driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); // It will scroll speed Thread.sleep(1000); driver.findElement(By.tagName("body")).sendKeys(Keys.DOWN); // wait for 1 second and Scroll } } }Wish you a very happy learning!
Saturday, 9 July 2016
Scroll with javascript&Action command
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment