滚动越来越页面的底部 [英] scroll the a growing page to the bottom

查看:126
本文介绍了滚动越来越页面的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面。当我手动滚动它,它的增长,然后我可以直到滚动到达底部(一个很好的例子是Facebook的时间轴页)一次又一次地滚动它。

I have a page. when I scroll it manually, it grows and then I can scroll it again and again until the scroll arrives to the bottom (a good example is a facebook timeline page).

我试着写:

static IWebDriver driver = new ChromeDriver(@"C:\selenium\net40");
IJavaScriptExecutor js = driver as IJavaScriptExecutor;



然后我进入了一个页面,做的:

then I entered a page and did:

js.ExecuteScript("window.scroll(0, document.height)");



但我可以滚动以上。

but I can scroll more.

我怎么能使其滚动至底部,即使页面的增长?

how can I make it to scroll to the bottom even if the page is growing?

感谢任何帮助!

推荐答案

window.scroll(0,document.height)将滚动到已知的滚动区域。问题是,当你到达页面的底部提供了更多的数据被下载。这样,可滚动区域被改变。您需要滚动根据需要多次。

window.scroll(0, document.height) will scroll to the known scrollable area. The problem is that more data are downloaded when you reach bottom of the page. So, the scrollable area is changed. You need to scroll as many times as required.

例如使用这个脚本

var timeId = setInterval( function() {
    if(window.scrollY!==document.body.scrollHeight)
        window.scrollTo(0,document.body.scrollHeight);
    else
        clearInterval(timeId);
},500);



编辑:

在某些页面, window.scrollY 将永远不等于 document.body.scrollHeight ,所以setIntervanl会永远不会被清除。这将阻止你去顶

On some pages, window.scrollY will never be equal to document.body.scrollHeight, so setIntervanl will never be cleared : this will prevent you to go to top.

var timeId = setInterval( function() {
    if(window.scrollY<(document.body.scrollHeight-window.screen.availHeight))
        window.scrollTo(0,document.body.scrollHeight);
    else
    {
        clearInterval(timeId);
        window.scrollTo(0,0);
    }
},500);

这篇关于滚动越来越页面的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆