如何滚动到div元素的底部Selenium Webdriver [英] How to scroll to bottom of div element Selenium Webdriver

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

问题描述

我有一个用例,其中网页上有一个div元素,单击链接后,它看起来像一个弹出对话框(它不是实际的弹出窗口,类似对话框,当您单击链接以查看您对信息的反应等)

I have a use case wherein there's a div element on the webpage, it appears like a popup dialog as soon as you click a link (its not an actual popup, its something like dialog boxes which opens in Facebook when you click a link to check reactions on your posts etc.)

我正在使用带有Java的Selenium WebDriver来自动化此应用程序的测试,我的用例涉及到我滚动到对话框的底部,在该对话框的底部有一个链接,可以显示更多的项目,当用户单击以显示更多的项目时,它将填充列表中的其他10个项目,依此类推,直到没有其他项目可供用户访问为止.

I'm using Selenium WebDriver with Java to automate tests for this application, my use case involves me to scroll to the bottom of the dialog box where there is a link to show more items, when user clicks show more, it populates another 10 items in the list and so on until there are no other items left for the user to visit.

因此,基本上,我必须向下滚动该特定的div元素,直到继续看到Show More链接,并且当驱动程序无法找到显示更多链接时,它应该停止.

So basically I have to scroll down on that particular div element till I keep seeing Show More link and when driver is not able to find show more link it should stop.

注意-我不能只使用javascript window.scrollTo()滚动到页面底部,因为它会向下滚动到整个网页,但是我只想滚动到该除法元素的底部.

Note - I can't just scroll to bottom of the page using javascript window.scrollTo() as it will scroll down through whole webpage, however I just want to scroll to bottom of that division element only.

如果有人对如何实现这一目标有任何想法,请告诉我.

If anybody have any idea on how to achieve this please let me know.

感谢您的提前帮助!

推荐答案

滚动到任何可滚动元素内部(底部)的另一种方法:

Another way of scrolling to the bottom inside (of) any scroll-able element:

public void scrollToBottomInsideDiv(WebElement scrollArea) {
    JavascriptExecutor js = ((JavascriptExecutor) webdriver);
    js.executeScript("arguments[0].scrollTo(0, arguments[0].scrollHeight)", scrollArea);
}

这篇关于如何滚动到div元素的底部Selenium Webdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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