import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.*;
import org.testng.annotations.Test;
public class ScrollDownTestAnkurDemo {
@Test
public static void getDynamicScrollDownByAnkur() {
WebDriver driver = WebDriverManager.chromedriver().create();
driver.manage().window().maximize();
driver.get("https://www.google.com");
driver.findElement(By.name("q")).sendKeys("Facebook"+ Keys.ENTER);
JavascriptExecutor js = (JavascriptExecutor) driver;
//Get the actual whole WebPage Height
Object height = js.executeScript("return document.body.scrollHeight");
String ht = height.toString();
System.out.println("Page height is : "+ht);
//Calculating the Number of Steps to scroll using 450 Pixel in each scroll
float htInt = Integer. parseInt(ht);
System.out.println(" The number of steps to scroll down with each 450 px :"+Math.round(htInt/450));
int y = 0;
int z = 450;
for(int i = 0 ; i < Math.round(htInt/450)-1 ; i ++){
js.executeScript("window.scrollBy(" + y + "," + z + ")","");
y=z;
z=z+450;
System.out.println(" After Execution the scroll height y :"+y +" z is :"+z);
}
driver.quit();
}
}
Comments
Post a Comment