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脚本

 
以下备注所用test.html 的代码(我也是在网上找的,简单的修改显示文字而已),供大家使用:

<!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 控制滚动条的更多相关文章

  1. javascript控制滚动条的位置,获取控件的位置

    一.如下是定位鼠标在视窗中的位置,先定位视窗和页面直接的距离. function getMousePoint() { var point = {x:0,y:0}; // 如果浏览器支持 pageYOf ...

  2. selenium执行JavaScript语句:控制滚动条 聚焦元素 改变下拉选项

    1. 执行js脚本 控制滚动条 # http://www.cnblogs.com/yoyoketang/p/6128655.html In [347]: js = "window.scrol ...

  3. 使用selenium控制滚动条(非整屏body)

    方法原理:     (1)使用jQuery CSS 操作 - scrollTop() 方法,设置 <div> 元素中滚动条的垂直偏移,语法:$(selector).scrollTop(of ...

  4. Java&Selenium控制滚动条方法封装

    Java&Selenium控制滚动条方法封装 package util; import org.openqa.selenium.JavascriptExecutor; import org.o ...

  5. Java&Selenium 鼠标键盘及滚动条控制相关方法封装

    一.摘要 本片博文主要展示在使用Selenium with java做web自动化时,一些不得不模拟鼠标操作.模拟键盘操作和控制滚动条的java代码 二.模拟鼠标操作 package util; im ...

  6. 【转】selenium技巧 - 通过js来控制滚动条,通过xpath定位最上层的div层

    http://blog.csdn.net/iceryan/article/details/8162703 业务流程:   1.打开此网页 http://nanjing.xiaomishu.com/sh ...

  7. BDD测试之selenium控制滚动条

    一.对于页面存在滚动条,可以通过插入JS控制滚动条(最常用的方法) (1)将滚动条移动到指定坐标位置处 ((JavascriptExecutor) driver).executeScript(&quo ...

  8. [TimLinux] JavaScript 代码控制滚动条移动到顶部/底部

    1. scrollIntoView函数 这个函数控制滚动条顶部内容.还是底部内容呈现在视图窗口中,接收一个参数:boolean值. true: 顶部出现在视图窗口中 false: 底部存在在视图窗口中 ...

  9. 自动化测试-13.selenium执行JS处理滚动条

    前言 selenium并不是万能的,有时候页面上操作无法实现的,这时候就需要借助JS来完成了. 常见场景: 当页面上的元素超过一屏后,想操作屏幕下方的元素,是不能直接定位到,会报元素不可见的. 这时候 ...

随机推荐

  1. canvas象棋 画图

    今天写了一个canvas画图的象棋 .js基础不行,只画了个图,以后补充... <!DOCTYPE html> <html lang="en"> <h ...

  2. webpack配置自动打包重新运行npm run dev出现报错

    webpack配置自动打包重新运行npm run dev出现报错 运行npm run dev出现如下报错 Listening at http://localhost:8080(node:2328) U ...

  3. HDU-1312题解(DFS)

    HDU-1312-DFS Written by Void-Walker    2020-02-01 09:09:25 1.题目传送门:http://acm.hdu.edu.cn/showproblem ...

  4. Regression 回归——多项式回归

    回归是指拟合函数的模型.图像等.与分类不同,回归一般是在函数可微的情况下进行的.因为分类它就那么几类,如果把类别看做函数值的话,分类的函数值是离散的,而回归的函数值通常是连续且可微的.所以回归可以通过 ...

  5. 嵊州普及Day3T1

    题意:n座山,每天袭击k面,不能为同一座.问最少几天袭击所有山两面. 思路:不管如何,n,k<=10,做了就能过,考试时先想的暴力模拟,后来发现有规律,看看就好了. 见代码: #include& ...

  6. 公用表表达式(CTE) with as 片段

    1.为什么用CTE,而不用表变量, declare @t table(CountryRegionCode nvarchar(3)) insert into @t(CountryRegionCode)  ...

  7. 050、Java中使用switch判断,使用字符串判断

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  8. Consul 简介及集群安装

    简介 Consul是基于GO语言开发的开源工具,主要面向分布式,服务化的系统提供服务注册.服务发现和配置管理的功能. Consul的功能都很实用,其中包括:服务注册/发现.健康检查.Key/Value ...

  9. SSH和SFTP的简单使用

    ssh命令 ssh 命令用来远程登录linux主机:ssh username@hostname 默认端口是22,如果设定了其他端口,那么使用-p参数来指明,例如端口若改为6666, 则登录命令变为 s ...

  10. Linux添加虚拟内存 && 修改Linux系统语言

    Linux添加虚拟内存 首先执行free -h查看内存状况: total used free shared buff/cache available Mem: 1.8G 570M 76M 8.4M 1 ...