[英]How to scroll down a specific div of page having pagination using selenium webdriver
I am trying to scroll down page and get the last element of that section/div. 我试图向下滚动页面并获取该部分/ div的最后一个元素。 i have executed the code:
我已经执行了代码:
Coordinates coordinate = ((Locatable)element).getCoordinates();
coordinate.inViewPort();
and also tried with 并尝试了
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(0, 250)");
But it is scrolling the entire page instead of scrolling the specific section 但是它正在滚动整个页面,而不是滚动特定的部分
And also the page has pagination 页面也有分页
First you need to find the element you're trying to scroll to: 首先,您需要找到要滚动到的元素:
WebElement element = driver.findElement(By.xpath("xpath_here")); //or anything else used to identify the element
Afterwards, you can execute JS using JavascriptExecutor
to bring the element into view using scrollIntoView()
: 之后,您可以使用
JavascriptExecutor
执行JS,以使用scrollIntoView()
将元素显示在视图中:
((JavaScriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", element);
What you have tried will scroll the window scroll bar, try something like below 您尝试过的操作将滚动窗口滚动条,尝试如下操作
JavascriptExecutor je = (JavascriptExecutor) dr;
je.executeScript("arguments[0].scrollIntoView(true);",dr.findElement(By...));
Specify the locator of the element which you are trying to find by scrolling down. 通过向下滚动指定要查找的元素的定位符。
arguments[0] 参数[0]
Edit: 编辑:
JavascriptExecutor je = (JavascriptExecutor) dr;
je.executeScript("arguments[0].scrollTop(arguments[0].scrollHeight);",dr.findElement(By...));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.