![](/img/trans.png)
[英]Rails 4: Loading posts w/ JQuery & AJAX on a “Load More” button
[英]Watir wait for more posts load
我要抓取的網站正在通過滾動事件進行延遲加載。 (無限滾動)我想等待更多的帖子加載,但是所有帖子都具有相同的類名。 因此,我等不及要加載具有特定類名的元素。 我不想使用sleep()
方法。
示例代碼:
<div class='posts'>
<div class='single-post'></div>
<div class='single-post'></div>
<div class='single-post'></div>
<div class='single-post'></div>
// The following posts appear after scrolling. I want to fetch these posts
<div class='single-post'></div>
<div class='single-post'></div>
<div class='single-post'></div>
<div class='single-post'></div>
</div>
我該如何解決這個問題? 是否可以檢查該div是否有10個以上的帖子?
思考?
您可以獲取單個帖子div的集合,以查看是否已加載更多。 根據頁面的標記,您可以執行以下操作:
browser.divs(class: 'single-post').count
或者,如果父母很重要:
browser.div(class: 'posts').divs(class: 'single-post').count
這可以用於等待帖子數量增加:
# Find the original count
original_count = browser.divs(class: 'single-post').count
# Take an whatever action to trigger the loading of more posts
browser.scroll.to :bottom
# Wait for the count to increase
browser.wait_until do
new_count = browser.divs(class: 'single-post').count
new_count > original_count
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.