如何向下滚动到动态加载网页的末尾?

How can I scroll down to the end of a dynamically loading webpage?

我们谈论的是一个网页,在某种程度上,您可以向下滚动新元素。

我试过了:

1.WebUI.scrollToElement(findTestObject('footer'), 30)

2.WebUI.executeJavaScript('window.scrollTo(0, document.documentElement.scrollHeight)', [])

3.WebUI.executeJavaScript('window.scrollTo(0, document.body.scrollHeight)', [])

4.WebUI.executeJavaScript(‘window.scrollTo(0, **923** )’, [])

…但是 none 到页面末尾。还有其他想法吗?

我发现这个脚本可以完成“工作”:

try { 
  long lastHeight=((Number) WebUI.executeJavaScript("return document.body.scrollHeight", null)).longValue(); 

  while (true) { 
    WebUI.executeJavaScript("window.scrollTo(0, document.body.scrollHeight);", null);
    Thread.sleep(2000);
    long newHeight = ((Number)WebUI.executeJavaScript("return document.body.scrollHeight", null)).longValue();
    if (newHeight == lastHeight) { 
      break;
    } 
    lastHeight = newHeight;
  } 
} catch (InterruptedException e) {
 e.printStackTrace();
}