如何用selenium滚动页面 [英] How to scroll page with selenium

查看:104
本文介绍了如何用selenium滚动页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FirefoxDriver webdriver。在firefox窗口中加载的页面是一个大页面,我想使用selenium滚动该页面。

I am using FirefoxDriver webdriver. The page that loads in firefox window is a large page and I want to scroll that page using selenium.

我想知道如何做到这一点。

I want to know how this can be done.

谢谢。

推荐答案

如果你想使用selenium webdriver滚动firefox窗口,其中一种方法是在java代码中使用javaScript,向下滚动的javeScript代码如下:

If you want to scroll on the firefox window using selenium webdriver, one of the way is to use javaScript in the java code, The javeScript code to scroll down is as follows:

WebDriver driver = new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("window.scrollTo(0,Math.max(document.documentElement.scrollHeight," + "document.body.scrollHeight,document.documentElement.clientHeight));");

这篇关于如何用selenium滚动页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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