0

I am trying to solve an issue where I need to check whether all the products in a web page loads completely. The products load only when the user scroll the page downwards. Each time on a scroll 8 products are loaded.

How to check in that page that the last product loads and user is now not able to scroll downwards?

  • What have you tried and what was the result? Please read the help topics on how to ask a good question. You need to research your own issue, find code samples, etc. and write your own code to solve the issue. If you do all that and still can't figure it out, then come back and edit your question and add notes from the research you did, the code you have tried, and what the result was... any error messages, etc. – JeffC Jul 03 '16 at 04:00

2 Answers2

0

I faced a similar issue as you. In my case I got a message saying more items were being loaded. Once I had loaded all items I no longer got this message. So the way I solved it was by creating a loop which scrolls to the bottom of the page, checks if more stuff is being loaded and breaks out of the loop once all is loaded.

Now if you don't have an element that indicated more items are loading you could use findElements() to get all the products and check the size of this list. Once all products are loaded the list will remain the same length.

JavascriptExecutor executor = (JavascriptExecutor) driver;
List<WebElement> products = driver.findElements(By.something, "locator");

int amount = 0;
while products.size() > amount {
    amount = products.size()
    // Scroll to the bottom of the page
    executor.executeScript("window.scrollTo(0, document.body.scrollHeight);");
    products = driver.findElements(By.something, "locator");
}
RemcoW
  • 4,196
  • 1
  • 22
  • 37
0

Use the known solution for scrolling down:

WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,250)", "");

Then check that 8 products after last scrolling iteration doesn't differ from current iteration. pseudo-code:

products = getProducts();
jse.executeScript("window.scrollBy(0,250)", "");
// reasonable wait here
if(getProducts() == products){
    //that it. nothing to scroll 
Community
  • 1
  • 1
Rudziankoŭ
  • 10,681
  • 20
  • 92
  • 192