简体   繁体   中英

Watir scroll down the page as long as there is more content to show

I want to scroll down the page as long as there is more content to show.

For example, when you click followers on Instagram, a dialog window will pop up and it will load more followers as you scroll down as long as there are more followers to show.

Instagram追随者对话框窗口

I could do this the hard way like getting the follower count and then counting the followers as I scroll down and when they equal stop scrolling there.

But I wanted to ask you whether there could be a better way.

You can check if a scrollable element is at the bottom by comparing its scrollTop and scrollHeight.

The following work:

scrollable = browser.div(class: 'j6cq2') # div with overflow-y=scroll
until browser.execute_script('return arguments[0].scrollTop + arguments[0].clientHeight >= arguments[0].scrollHeight', scrollable) do
    browser.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', scrollable)
    sleep(1)
end

Note that I didn't have time to find a better solution than using #sleep. However, hopefully this gives you an idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM