简体   繁体   English

Selenium Web驱动程序-如何检查页面中是否所有产品都已加载

[英]Selenium Web Driver - How to check whether all the products in a page loads

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. 每次滚动时,将加载8个产品。

How to check in that page that the last product loads and user is now not able to scroll downwards? 如何在该页面中检查是否加载了上一个产品,并且用户现在无法向下滚动?

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. 现在,如果您没有一个元素指示正在加载更多项目,则可以使用findElements()获取所有产品并检查此列表的大小。 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");
}

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. 然后检查last滚动迭代后的8个产品与current迭代是否相同。 pseudo-code: 伪代码:

products = getProducts();
jse.executeScript("window.scrollBy(0,250)", "");
// reasonable wait here
if(getProducts() == products){
    //that it. nothing to scroll 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查日期是否在Selenium Web驱动程序(Java)中的日期范围内 - Check whether dates are within the date range in selenium web driver ( Java) 如何使用Java逐一检查Selenium Web驱动程序中的所有复选框? - How to check all check-boxes one by one in selenium web driver with the java? 我想使用Selenium检查网页上是否存在框架,该怎么做 - I want to check whether frame exists or not on web page by using Selenium, how can do it Selenium Web驱动程序-如何在滚动时在运行时获取页面加载元素的情况下获取所有项目? - Selenium Web Driver - How to get all the items in case a page load element at the run time while scrolling down? 如何通过使用Java为Selenium Web驱动程序中的复选框编写脚本 - How to write the script for the check box in Selenium web driver by using Java 如何检查特定值显示在Selenium Web驱动程序的表中 - How to check a specific value is displayed inside a table in Selenium Web driver 如何使用Java中的Selenium Web驱动程序检查元素形成的csv文件? - how to check elements form a csv file with selenium web driver in java? 关闭selenium中的web驱动前如何验证文件下载是否完成? - How to verify whether file downloading is completed before closing the web driver in selenium? 页面加载和Selenium-驱动程序在加载后不执行任何操作 - Page loading and Selenium - Driver not doing anything after it loads 检查web上是否存在web页面 - Check whether web page exist on the web or not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM