使用selenium控制滚动条(非整屏body)
方法原理:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".btn1").click(function(){
$("#test div").scrollTop(100);
});
$(".btn2").click(function(){
alert($("div").scrollTop()+" px");
});
});
</script>
</head> <body>
<div id="test">
<div
style="border:1px solid black;width:200px;height:200px;overflow:auto">
This is some text. This is some text. This is some text. This is some
text. This is some text. This is some text. This is some text. This is
some text. This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text. This is some
text. This is some text. This is some text. This is some text. This is
some text. This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text. This is some
text. This is some text. This is some text. This is some text. This is
some text. This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</div>
</div>
<button class="btn1">把 scroll top offset 设置为 100px</button>
<br />
<button class="btn2">获得 scroll top offset</button> </body>
</html>
selenium代码:
本例中仅控制滚动条垂直移动
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait; public class TestScroll {
private WebDriver driver;
@Before
public void setUp(){
//login
System.setProperty("webdriver.ie.driver", "C:\\Program Files (x86)\\Internet Explorer\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
String url = "http://localhost:8080/test/MyJsp.jsp";
//l打开测试页面
driver.get(url);
WebDriverWait wait = new WebDriverWait(driver, 5);
try {
WebElement webElement = wait.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver webDriver) {
return webDriver.findElement(By.id("test"));
}
});
if(webElement==null){
System.out.println("页面还未加。。。。");
}else{
System.out.println("页面加载完成~~~~~~~~~~~");
JavascriptExecutor js = (JavascriptExecutor)driver;
//执行js脚本,控制滚动条滚动
js.executeScript("$('#test div').scrollTop(100);");
Thread.sleep(10000);
}
} catch (TimeoutException e) {
System.out.println("打不开链接。。。。。");
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
} @Test
public void testLogic(){
} @After
public void tearDown(){
if(driver!=null){
driver.quit();
}
} }
使用selenium控制滚动条(非整屏body)的更多相关文章
- Java&Selenium控制滚动条方法封装
Java&Selenium控制滚动条方法封装 package util; import org.openqa.selenium.JavascriptExecutor; import org.o ...
- BDD测试之selenium控制滚动条
一.对于页面存在滚动条,可以通过插入JS控制滚动条(最常用的方法) (1)将滚动条移动到指定坐标位置处 ((JavascriptExecutor) driver).executeScript(&quo ...
- selenium执行JavaScript语句:控制滚动条 聚焦元素 改变下拉选项
1. 执行js脚本 控制滚动条 # http://www.cnblogs.com/yoyoketang/p/6128655.html In [347]: js = "window.scrol ...
- 通过selenium控制浏览器滚动条
目的:通过selenium控制浏览器滚动条 原理:通过 driver.execute_script()执行js代码,达到目的 driver.execute_script("window.sc ...
- 【转】selenium技巧 - 通过js来控制滚动条,通过xpath定位最上层的div层
http://blog.csdn.net/iceryan/article/details/8162703 业务流程: 1.打开此网页 http://nanjing.xiaomishu.com/sh ...
- Selenium系列(22) - 通过selenium控制浏览器滚动条的几种方式
如果你还想从头学起Selenium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1680176.html 其次,如果你不懂前端基础知识, ...
- [Python爬虫] 之五:Selenium 处理滚动条
selenium并不是万能的,有时候页面上操作无法实现的,这时候就需要借助JS来完成了. 当页面上的元素超过一屏后,想操作屏幕下方的元素,是不能直接定位到,会报元素不可见的.这时候需要借助滚动条来拖 ...
- CSS 控制滚动条样式
/*作为IT界最前端的技术达人,页面上的每一个元素的样式我们都必须较真,就是滚动条我们也不会忽略.下面我给大家分享一下如何通过CSS来控制滚动条的样式,代码如下:*/ 1 /*定义滚动条轨道*/ #s ...
- delphi 发送消息控制滚动条
1.Perform 函数 DBGrid1.Perform(WM_VSCROLL,SB_PAGEDOWN,0); //控制滚动条,向后翻页 DBGrid1.Perform(WM_VSCROLL,SB_ ...
随机推荐
- oozie调用shell
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agree ...
- PL/SQL Developer 和 instantclient客户端安装配置(图文)
一: PL/SQL Developer 安装 下载安装文件安装,我这里的版本号是PLSQL7.1.4.1391,安装目录是:D:\soft\PLSQLDeveloper 二:instantclient ...
- rsync 通过 ssh 上传文件
rsync -avzP /www/ -e ssh root@192.168.1.200:/www/ 批处理上传: #!/bin/bash for (( ; ; )) do rsync -avzP /w ...
- My SQL的内连接,外链接查询
1.内连接:只连接匹配的行. 2.左外连接:包含左边表的全部行,以及右边表中所有匹配的行,无论右边的表有没有和左边匹配的行,左边的所有行都必须要显示. 3.右外连接:包含右边表的全部行,以及左边表中所 ...
- Git本地提交到远程指定分支
git push origin master:ziranmeng2.(本地分支:远程分支)
- Tomcat启动时自动加载Servlet
1.想做一个服务启动时自动启动一不停止的获取订阅功能 2.之前是做一个Jsp页面请求servlet来触发方法 3.现在实现Tomcat启动时自动加载Servlet 1.Tomcat中启动Servlet ...
- SDcard
import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import ja ...
- 修改eclipse运行内存的大小
一. 尝试修改Eclipse.ini 文件 (此方法不行) 找到eclipse 目录下的eclipse.ini 文件,修改下面的内容: -Xms40m -Xmx512m 修改后重启eclipse ...
- unity3d游戏开发git环境配置
http://dmayance.com/git-and-unity-projects/ 主要是将2进制的项目文件设置成文本模式,这样便于比较修改. 部署了一个gitignore,忽略了不需要同步的项目 ...
- Calendar /String /Date 转换
Calendar 转化 String Calendar calendat = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDate ...