5.6 WebDriver API实例讲解(41-50)
41.操作Web页面的滚动条
(1)滑动页面的滚动条到页面的最下面。
(2)滑动页面的滚动条到页面的某个元素。
(3)滑动页面的滚动条向下移动某个数量的像素。
package apiSample; import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; public class TestDemo {
public WebDriver driver;
public String baseUrl; @BeforeMethod
public void beforeMethod(){
baseUrl="http://v.sogou.com";
System.setProperty("webdriver.gecko.driver", "MyDriver/geckodriver.exe");
driver =new FirefoxDriver();
driver.get(baseUrl);
}
//priority=1表示测试用例以第一优先级运行
@Test(priority=)
public void scrollingToBottomofAPage()
{
//使用JavaScript的scrollTo函数和document.body.scrollHeight参数将页面的滚动条滑动到页面的最下方
((JavascriptExecutor) driver).executeScript("window.scrollTo(0,document.body.scrollHeight)");
//停顿3秒,用于人工验证滚动条是否滑动到指定的位置。根据测试需要,可注释下面的停顿代码
try{
Thread.sleep();
}catch(InterruptedException e){
e.printStackTrace();
}
}
@Test(priority=)
public void scrollingToElementofAPage(){
WebElement element=driver.findElement(By.partialLinkText("综艺节目"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element);
try{
Thread.sleep();
}catch(InterruptedException e){
e.printStackTrace();
}
}
@Test(priority=)
public void scrollingByCoordinatesofAPage(){
((JavascriptExecutor) driver).executeScript("window.scrollBy(0,800)");
try{
Thread.sleep();
}catch(InterruptedException e){
e.printStackTrace();
}
} @AfterMethod
public void afterMethod(){
driver.quit();
}
}
5.6 WebDriver API实例讲解(41-50)的更多相关文章
- 5.7 WebDriver API实例讲解
本节主要详细描述WebDriver的常用API使用方法. 1.访问某网页地址 被测试网页的网址:http://www.sogou.com. Java语言版本的API实例代码: 方法1: public ...
- 5.6 WebDriver API实例讲解(16-30)
16.操作单选框 被测试的网页为Demo1. Java语言版本的API实例代码: public static void operateRadio(){ driver.get("file:// ...
- 5.6 WebDriver API实例讲解(31-35)
31.判断页面元素是否存在 public static void testElementExist(){ driver.get("http://www.sogou.com"); t ...
- 5.6 WebDriver API实例讲解(31-40)
31.判断页面元素是否存在 public static void testElementExist(){ driver.get("http://www.sogou.com"); t ...
- WebDriver API 实例详解(四)
三十一.使用页面的文字内容识别和处理新弹出的浏览器窗口 被测试网页的HTML源码: <html> <head> <meta charset="UTF-8&quo ...
- WebDriver API 实例详解(三)
二十一.模拟鼠标右键事件 被测试网页的网址: http://www.sogou.com Java语言版本的API实例代码: package test; import org.testng.annota ...
- WebDriver API 实例详解(二)
十一.双击某个元素 被测试网页的html源码: <html> <head> <meta charset="UTF-8"> </head&g ...
- WebDriver API 实例详解(一)
一.访问某网页地址 被测试网页的网址: http://www.baidu.com Java语言版本的API实例代码: 方法1: package test; import org.testng.anno ...
- python+selenium自动化软件测试(第2章):WebDriver API
2.1 操作元素基本方法 前言前面已经把环境搭建好了,从这篇开始,正式学习selenium的webdriver框架.我们平常说的 selenium自动化,其实它并不是类似于QTP之类的有GUI界面的可 ...
随机推荐
- ES6 Promise对象then方法链式调用
then()方法的作用是Promise实例添加解决(fulfillment)和拒绝(rejection)状态的回调函数.then()方法会返回一个新的Promise实例,所以then()方法后面可以继 ...
- 一篇搞定vue-router
由于Vue常见于前后端分离开发场景下,所以页面跳转工作全部交给了前端,所以基于集中管理的原则,就有了vue-router插件,它给定了url和组件之间的跳转规则 Demo准备 vue init web ...
- Java IO异常处理方式
public class IOException{ // 获取系统默认的行分隔符 private static final String LINE_SEPARATOR = System.getProp ...
- Java 之Object 类
Object 类: 所有类的根类, 是不断向上抽取而来, 具备着所有对象都具备的共性内容. 常用共性方法 boolean equals(Object obj) : 判断两个对象是否相等. 默认比较的是 ...
- java 子类不能继承父类的static方法
先来看一段代码 /** * Created by bjchengpeng on 2018/7/19. */ /**运行结果 * woof * woofaa * * woof * Basenjiaa * ...
- Milking Time---poj3616(简单dp)
题目链接:http://poj.org/problem?id=3616 题意:人从奶牛身上挤奶有m个时间段(1----n),每个时间段包含 s e f 表示从 s 到 e 的这段时间可以获得 f 单位 ...
- 部署Node.js的应用
原创:作者 mashihua 最近Node.js很火,让很多的前端看到了可以直接从前端写到后端的希望.但是每次部署一个Node.js的应用却让前端苦恼不已.每次登陆服务器,用自己不熟悉的方式从版本控制 ...
- python 多进程使用Queue通信的例子
import time from multiprocessing import Process,Queue MSG_QUEUE = Queue(5) def startA(msgQueue): whi ...
- PAT 1085 Perfect Sequence[难]
1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...
- 调色盘canvas
//调色盘 function draw8(id){ var canvas = document.getElementById(id); var context = canvas.getContext( ...