垂直向下滚动并使用java在Selenium WebDriver中向上滚动 [英] Vertical Scroll down and scroll up in Selenium WebDriver with java

查看:355
本文介绍了垂直向下滚动并使用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)", "");

这篇关于垂直向下滚动并使用java在Selenium WebDriver中向上滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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