Selenium - complete ajax loading autoscroll to bottom of page
automated-tests, java, selenium, selenium-webdriver
Solution
Try this approach:
//Get total height
By selBy = By.tagName("body");
int initialHeight = driver.findElement(selBy).getSize().getHeight();
int currentHeight = 0;
while(initialHeight != currentHeight){
initialHeight = driver.findElement(selBy).getSize().getHeight();
//Scroll to bottom
((JavascriptExecutor) driver).executeScript("scroll(0," + initialHeight + ");");
System.out.println("Sleeping... wleepy");
Thread.sleep(2000);
currentHeight = driver.findElement(selBy).getSize().getHeight();
}
Hope help!
Problem
I have a webpage where when you scroll to the bottom it then loads more results via ajax. You can do several iterations of this before it completes. Bit like what facebook does. I am trying to write a selenium script to keep going to the end of the page until it completes. Something like this sort of half completes it.. I just don't know how to determine if page is at the bottom - so i can put it inside a loop of some sort? My Attempt ``` By selBy = By.tagName("body"); driver.findElement(selBy).sendKeys(Keys.PAGE_DOWN); System.out.println("Sleeping... wleepy"); Thread.sleep(5000); driver.findElement(selBy).sendKeys(Keys.PAGE_DOWN); System.out.println("Sleeping... wleepy1"); Thread.sleep(3000); //etc... ``` Could Look like this? hasScroll() isnt a real method. I put that there to demonstrate what im trying to achieve ``` while (driver.findElement(By.tagName("body")).hasScroll()) { driver.findElement(selBy).sendKeys(Keys.PAGE_DOWN); System.out.println("Sleeping... wleepy"); Thread.sleep(2000); } ```