简体   繁体   English

如何使用Selenium WebDriver向下滚动具有分页的页面的特定div

[英]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.

相关问题 如何使用带有 Java 的 Selenium WebDriver 滚动特定的 DIV? - How to scroll a specific DIV using Selenium WebDriver with Java? 如何在 Java 中使用 Selenium WebDriver 向下滚动 - How to scroll down using Selenium WebDriver with Java 如何将Selenium WebDriver中的页面滚动到特定链接 - How to scroll the page in selenium webdriver to specific link 使用java在Selenium WebDriver(Selenium 2)中向上或向下滚动页面 - Page scroll up or down in Selenium WebDriver (Selenium 2) using java 如何向下滚动特定的div以查找元素并通过Java中的Selenium WebDriver单击它 - How to scroll down of specific div to locate an element and make it clickable via selenium webdriver in java 无法使用Selenium WebDriver和Java滚动特定的DIV - Unable to scroll a specific DIV using Selenium WebDriver with Java 使用 Selenium WebDriver 在网页内滚动特定的 DIV - Scroll a specific DIV inside a webpage using Selenium WebDriver 如何通过模拟Page Down Key使用Selenium向下滚动div容器? - How to scroll down a div container using Selenium by simulating the Page Down Key? 如何使用带有Java的Selenium WebDriver在分页中导航到第n页 - How to navigate to nth page in pagination using Selenium WebDriver with java 如何在 selenium webdriver 的下拉窗口中向下滚动? - How to scroll down in dropdown window in selenium webdriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM