Scroll to take screenshot in Chrome browser on Android device

Hi all,
I’m having an program that open ChromeBrowser on android device. If height of website is higher than window size then my program will take screenshot as each time screen is scroll.
Here is my code:

System.out.println(“Load done”);

    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(scrFile, new File("Screenshot.jpg"));
    Dimension size = driver.manage().window().getSize();
  //x position set to mid-screen horizontally
    int width = size.width/2;

    //Starting y location set to 80% of the height (near bottom)
    int startPoint = (int) (size.getHeight() * 0.95);
  //Ending y location set to 20% of the height (near top)
    int endPoint = (int) (size.getHeight() * 0.15);
    new TouchAction(driver).press(PointOption.point(width, startPoint))
    .waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000))).moveTo(PointOption.point(width, endPoint)).release().perform();
    File scrFile1 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(scrFile1, new File("Screenshot1.jpg"));

Now I want to use a for loop to control time to scroll and take screenshot but I don’t know what is the condition for the loop to stop :expressionless:
My idea is get the page height / window height = total time to scroll. Problem here is how to get total webpage height in ChromeBrowser.
Anyone know an idea about this?
P/s sorry for my bad English :stuck_out_tongue: