【转】Selenium 利用javascript 控制滚动条
http://luyongxin88.blog.163.com/blog/static/92558072011101913013149/
< xmlnamespace prefix ="o" ns ="urn:schemas-microsoft-com:office:office" />
在工作中,遇到这样的问题,注册时的法律条文需要阅读,判断用户是否阅读的标准是:滚动条是否拉到最下方。以下是我模拟的2种情况:
1. 滚动条在上方时,点击submit用户,提示:please view top new terms!

2. 滚动条在最下方,点击submit用户,提示:Thanks!

以上如果是手动测试显然很简单,那么如何用selenium测试呢。
经过IDE录制,发现拖动滚动条的动作并没有录制下来!那么能想到的方法只有利用javascript来设置了。

Baidu后得到的知识是:
<body onload= "document.body.scrollTop=0 ">

也就是说如果scrollTop=0 时,滚动条就会默认在最上方
<body onload= "document.body.scrollTop=100000 ">

也就是说如果scrollTop=100000 时,滚动条就会默认在最下方
通过以上,以及学习的selenium调用javascript的知识:
在javascript中调用页面上的元素的方法
this.browserbot.getUserWindow().document.getElementById('text')
这样设置元素的属性就很简单了
this.browserbot.getUserWindow().document.getElementById('text').scrollTop=10000"
经过修改的IDE脚本

|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Selenium Study</title> <script language="JavaScript"> function check(){ var clientHeight = document.getElementById('text').clientHeight; var scrollTop = document.getElementById('text').scrollTop; var scrollHeight = document.getElementById('text').scrollHeight; if(clientHeight + scrollTop < scrollHeight){ alert("Please view top news terms !"); return false; }else{ alert("Thanks !"); } } function set() { document.getElementById('text').scrollTop=10000; } </script> </head> <body> <form id="form1" method="post" onsubmit="return check();"> <textarea id="text" name="text" cols="70" rows="14"> Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency. Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency. Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency. Selenium IDE is the a Firefox plugin that does record-and-playback of interactions with the browser. Use this to either create simple scripts, assist in exploratory testing. It can also export Remote Control or WebDriver scripts, though they tend to be somewhat brittle and should be overhauled into some sort of Page Object-y structure for any kind of resiliency. </textarea><br /><br /> <input type="submit" id="submit" name="submit" value="Submit" /> </form> </body> </html> |
【转】Selenium 利用javascript 控制滚动条的更多相关文章
- javascript控制滚动条的位置,获取控件的位置
一.如下是定位鼠标在视窗中的位置,先定位视窗和页面直接的距离. function getMousePoint() { var point = {x:0,y:0}; // 如果浏览器支持 pageYOf ...
- selenium执行JavaScript语句:控制滚动条 聚焦元素 改变下拉选项
1. 执行js脚本 控制滚动条 # http://www.cnblogs.com/yoyoketang/p/6128655.html In [347]: js = "window.scrol ...
- 使用selenium控制滚动条(非整屏body)
方法原理: (1)使用jQuery CSS 操作 - scrollTop() 方法,设置 <div> 元素中滚动条的垂直偏移,语法:$(selector).scrollTop(of ...
- Java&Selenium控制滚动条方法封装
Java&Selenium控制滚动条方法封装 package util; import org.openqa.selenium.JavascriptExecutor; import org.o ...
- Java&Selenium 鼠标键盘及滚动条控制相关方法封装
一.摘要 本片博文主要展示在使用Selenium with java做web自动化时,一些不得不模拟鼠标操作.模拟键盘操作和控制滚动条的java代码 二.模拟鼠标操作 package util; im ...
- 【转】selenium技巧 - 通过js来控制滚动条,通过xpath定位最上层的div层
http://blog.csdn.net/iceryan/article/details/8162703 业务流程: 1.打开此网页 http://nanjing.xiaomishu.com/sh ...
- BDD测试之selenium控制滚动条
一.对于页面存在滚动条,可以通过插入JS控制滚动条(最常用的方法) (1)将滚动条移动到指定坐标位置处 ((JavascriptExecutor) driver).executeScript(&quo ...
- [TimLinux] JavaScript 代码控制滚动条移动到顶部/底部
1. scrollIntoView函数 这个函数控制滚动条顶部内容.还是底部内容呈现在视图窗口中,接收一个参数:boolean值. true: 顶部出现在视图窗口中 false: 底部存在在视图窗口中 ...
- 自动化测试-13.selenium执行JS处理滚动条
前言 selenium并不是万能的,有时候页面上操作无法实现的,这时候就需要借助JS来完成了. 常见场景: 当页面上的元素超过一屏后,想操作屏幕下方的元素,是不能直接定位到,会报元素不可见的. 这时候 ...
随机推荐
- CSS3实现放大缩小动画
HTML <div> <div style="height: 35px;width:300px;background:orangered;border-radius: 4p ...
- mysql 三表索引优化
建表语句 CREATE TABLE IF NOT EXISTS `phone`( `phoneid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `card` ...
- VS中MFC项目文件特别大的解决办法
转 来自http://m.zhizuobiao.com/vc/vc-18082800177/ 自己插个眼 项目文件比较大因为 项目下有个隐藏文件夹.vs 下面是解决办法 本文主要向大家介绍了VC编程 ...
- JuJu团队1月2号工作汇报
JuJu团队1月2号工作汇报 JuJu Scrum 团队成员 今日工作 剩余任务 困难 飞飞 -- 测试dataloader 无 婷婷 调试代码 提升acc 无 恩升 -- 测试dataloade ...
- P1066 图像过滤
P1066 图像过滤 转跳点:
- JS写一个列表跑马灯效果--基于touchslide.js
先放上效果图: 类似于这样的,在列表中循环添加背景样式的跑马灯效果. 准备引入JS插件: <script type="text/javascript" src="x ...
- 关于 float 型和 double 型的区别,以及 char 型和 String 型的不同
一.1.float是单精度浮点数,内存分配4个字节,占32位,有效小数位6-7位 double是双精度浮点数,内存分配8个字节,占64位,有效小数位15位 2.java中默认声明的小数是double类 ...
- Typescript 实战 --- (9)ES6与CommonJS的模块系统
1.ES6模块系统 1-1.export 导出 (1).单独导出 // a.ts export let a = 1; (2).批量导出 // a.ts let b = 2; let c = 3; ex ...
- Day8 - G - Bound Found ZOJ - 1964
Signals of most probably extra-terrestrial origin have been received and digitalized by The Aeronaut ...
- Python 3.8 新功能【新手必学】
Python 3.8 是 Python 编程语言的最新主要版本, 它包含许多新功能和优化. Python 3.8 Python 3.8 的一些新功能包括: 1. 海象运算符 PS:很多人 ...