public class ScrollingPage {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver","C:\\Drivers\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.countries-ofthe-world.com/flags-of-the-world.html");
driver.manage().window().maximize();
JavascriptExecutor js=(JavascriptExecutor)driver;
//1. Scroll down page by pixel
// js.executeScript("window.scrollBy(0,1500)","");
// Long value=(Long)js.executeScript("return window.pageYOffset;");
// System.out.println("Number of pixels scrolled:"+value);
//2. Scroll down page till element is visible
// WebElement flag=driver.findElement(By.xpath("//tbody/tr[91]/td[1]/img[1]"));
//
//
// js.executeScript("arguments[0].scrollIntoView();",flag);
// Long value=(Long)js.executeScript("return window.pageYOffset;");
// System.out.println("Number of pixels scrolled:"+value);
//
//3.End of the page
js.executeScript("window.scrollBy(0,document.body.scrollHeight)");
Long value=(Long)js.executeScript("return window.pageYOffset;");
System.out.println("Number of pixels scrolled:"+value);
Thread.sleep(5000);
js.executeScript("window.scrollBy(0,-document.body.scrollHeight)"); //move to initial point
_________CONSOLE WINDOW______
Exception in thread "main" java.lang.ClassCastException: class java.lang.Double cannot be cast to class java.lang.Long (java.lang.Double and java.lang.Long are in module java.base of loader 'bootstrap') at .ScrollingPage.main(ScrollingPage.java:39)