利用下面的例子来编写测试脚本

页面代码:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>CheckBox</title>
<link
href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css"
rel="stylesheet" />
<script
src="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.js"></script>
</head>
<body>
<h3>checkbox</h3>
<div class="well">
<form class="form-horizontal">
<div class="control-group">
<label class="control-lable" for="c1">checkbox1</label>
<div class="controls">
<input type="checkbox" id="c1" />
</div>
</div>
<div class="control-group">
<label class="control-lable" for="c2">checkbox2</label>
<div class="controls">
<input type="checkbox" id="c2" />
</div>
</div>
<div class="control-group">
<label class="control-lable" for="c3">checkbox3</label>
<div class="controls">
<input type="checkbox" id="c3" />
</div>
</div>
</form>
</div>
</body>
</html>

脚本:

package com.test.findelement;

import java.util.Iterator;
import java.util.List; import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver; public class CheckBox { public static void main(String[] args) {
// TODO Auto-generated method stub WebDriver driver = new FirefoxDriver();
driver.get("file:///D:/10-selenium/workspace/SeleniumTest/src/com/test/findelement/checkbox.html");
driver.manage().window().maximize(); List<WebElement> WebElements = driver.findElements(By.cssSelector("[type=checkbox]")); Iterator iterator = WebElements.iterator(); //全部勾选
while(iterator.hasNext()){
WebElement wb = (WebElement)iterator.next();
wb.click();
}
//去掉第一个
waitTime(3000);
driver.findElements(By.cssSelector("[type=checkbox]")).get(0).click(); //去掉最后一个
waitTime(3000);
driver.findElements(By.cssSelector("[type=checkbox]")).get(WebElements.size()-1).click(); waitTime(5000);
driver.quit();
} static public void waitTime(int time) { try {
Thread.sleep(time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }

最新文章

  1. NSURLSession详解
  2. Django分析之三级下拉菜单选择省/市/县
  3. iOS 面试题(二):什么时候在 block 中不需要使用 weakSelf --转自唐巧
  4. linux---------------centos6.4安装完了以后敲ifconfig,没有局域网ip。解决如下
  5. 安装JDK,Python SDK及环境变量的配置
  6. 《利用Python进行数据分析》第4章学习笔记
  7. vs 2013 编译zlib
  8. redis来共享各个服务器的session,并同时通过redis来缓存一些常用的资源,加快用户获得请求资源的速度(转)
  9. ImageLoader的Jar包加载图片
  10. 【Linux Tips】登陆,提示符,别名
  11. 小白的Python之路 day5 time,datatime模块详解
  12. pycaffe︱caffe中fine-tuning模型三重天(函数详解、框架简述)
  13. python实例一
  14. fiddler抓包App数据
  15. Newtonsoft.Json WindowPhone7.1
  16. TFS2018 连接 K8S集群的方法
  17. Resource interpreted as Stylesheet but transferred with MIME type text/plain
  18. android 模仿今日头条ViewPager+TabLayout
  19. .Net Mvc5Filter与权限认证扩展
  20. Java获取中文拼音、中文首字母缩写和中文首字母

热门文章

  1. navicat 快速复制表所有字段
  2. python标准库介绍——2 os.path模块详解
  3. 配置 Sliverlight 跨域访问策略
  4. 自己写的一个操作Mysql的简单的实例
  5. C#用ado.net访问EXCEL的常见问题及解决方法
  6. perl的匿名引用
  7. 苹果开发小记(一):NSString 的比较用法
  8. Linux虚拟内存系统常用参数说明
  9. java动态代理的两种方法
  10. cocos2d-x -- removeChild