垂直向下滚动并使用java在Selenium WebDriver中向上滚动

垂直向下滚动并使用java在Selenium WebDriver中向上滚动

问题描述:

有人可以帮助我使用 Java 使用 WebDriver 自动执行向下滚动功能吗?

Can anybody please help me out to automate scroll down functionality with WebDriver using Java?

在我的情况下,对于雅虎邮件登录一旦我垂直向下滚动鼠标就会显示(可见)。

In my case, For yahoo mail "Sign In" is getting displayed (visible) once I scroll down the mouse vertically.

您可以使用以下代码垂直向下滚动:

You can scroll down vertically by using the following code:

((JavascriptExecutor) driver).executeScript("scroll(0,250);");

同样,也可以通过将y坐标更改为负数来向上滚动:

Similarly, it is also possible to scroll up by changing y coordinate as negative:

((JavascriptExecutor) driver).executeScript("scroll(0, -250);");

您还可以使用以下代码:
向下滚动:

You can also use the following code: For scroll down:

((JavascriptExecutor) driver).executeScript("window.scrollBy(0,250)", "");

向上滚动:

((JavascriptExecutor) driver).executeScript("window.scrollBy(0, -250)", "");