使用Selenium WebDriver(又称Selenium 2.0)向下滚动鼠标-JAVA [英] Mouse scroll down using Selenium WebDriver (a.k.a. Selenium 2.0) - JAVA

查看:760
本文介绍了使用Selenium WebDriver(又称Selenium 2.0)向下滚动鼠标-JAVA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在自动化测试(Selenium Webdriver)中进行鼠标滚动.我的页面上有大量数据,需要花费一些时间来加载所有数据.

I am trying to do a mouse scroll in my automation testing (selenium webdriver). My page have loads of data where it take time to load all the datum.

我的要求: 我有一个包含基准的合并表,其中这些记录是从显示在页面底部的一组值中显示的.

My Requirement: I have a consolidated table with set of datum, where those records are displayed from the set of values that get displayed in the bottom of my page.

我正在验证两个值是否相等,因为我需要完全滚动页面以求出相同的值.

I am validating whether both the values are equal, for that I need the page to be completely scrolled to evaluate the same.

我使用了以下代码:

Javascript jse = (Javascript)driver;
jse.executescript("scroll(0, 9000)");

这无助于它仅滚动了原点的一半,因此我的测试失败了.

This doesn't help it scrolled only half of the datum so my test get fail.

建议...

推荐答案

//鼠标向下滚动

JavascriptExecutor Scrool = (JavascriptExecutor) driver;
Scrool.executeScript("window.scrollBy(0,300)", "");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

滚动后即可找到元素

driver.findElement(By.xpath(""));

//鼠标向上滚动

JavascriptExecutor Scrool = (JavascriptExecutor) driver;
Scrool.executeScript("window.scrollBy(0,-300)", "");

//要使用上面的代码,请在下面的实用程序中导入

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.WebDriver;

这篇关于使用Selenium WebDriver(又称Selenium 2.0)向下滚动鼠标-JAVA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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