Selenium Webdriver——Table类封装
WebTable.java
import java.util.List; import org.openqa.selenium.By;
import org.openqa.selenium.WebElement; public class WebTable { private WebElement webTable;
public WebTable(WebElement webElement){
this.webTable = webElement;
} //等到表格的行数
public int getRowCount(){
List<WebElement>rowCounts = webTable.findElements(By.tagName("tr"));
return rowCounts.size();
} //得到指定行的列数
public int getColCount(int rowId){
List<WebElement>rowCounts = webTable.findElements(By.tagName("tr"));
//取得当前的tr
WebElement rowNum = rowCounts.get(rowId);
//计算当前的td数
List<WebElement>colCounts =rowNum.findElements(By.tagName("td"));
return colCounts.size();
} // 得到指定单元格的内容
public String getCellText(int rowIdx, int colIdx) { String text = ""; try{
List<WebElement> rowCounts = webTable.findElements(By.tagName("tr"));
WebElement currentRow = rowCounts.get(rowIdx);
List<WebElement> td = currentRow.findElements(By.tagName("td"));
WebElement cell = td.get(colIdx);
text = cell.getText();
}catch(IndexOutOfBoundsException e){
System.out.println("超出table边界值");
} return text;
}
}
对webTable类进行测试
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test; public class testTable { @Test
public void testTableWebElement() { WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("F:\\table.html");
WebTable webtable = new WebTable(driver.findElement(By.tagName("table")));
Assert.assertEquals(4, webtable.getRowCount());
Assert.assertEquals(5, webtable.getColCount(1));
System.out.println( webtable.getCellText(1, 1));
driver.quit();
}
}
Selenium Webdriver——Table类封装的更多相关文章
- selenium - webdriver - Keys类(键盘操作)
Keys()类提供了键盘上几乎所有按键的方法,这个类可用来模拟键盘上的按键,包括各种组合键,如 Ctrl+A, Ctrl+X,Ctrl+C, Ctrl+V 等等 from selenium impor ...
- selenium - webdriver - ActionChains类(鼠标操作)
ActionChains 类提供了鼠标操作的常用方法: perform(): 执行所有 ActionChains 中存储的行为: context_click(): 右击: double_click() ...
- Java+selenium之WebDriver的常用方法封装(八)
总结:WEB UI自动化测试一般采用 POP(面向页面编程),自动化测试框架分三层,有时如果页面如果太多,不好管理,可以面向控件编程,即把控件当作页面,毕竟控件是有限的,所以封装页面的代码量会少很多, ...
- Selenium Webdriver——处理Table
html table是由 table 元素以及一个或多个 tr.th 或 td 元素组成.如下: HTML源码如下: <html> <head> <meta http-e ...
- Selenium_用selenium webdriver实现selenium RC中的类似的方法
最近想总结一下学习selenium webdriver的情况,于是就想用selenium webdriver里面的方法来实现selenium RC中操作的一些方法.目前封装了一个ActionDrive ...
- selenium webdriver 右键另存为下载文件(结合robot and autoIt)
首先感谢Lakshay Sharma 大神的指导 最近一直在研究selenium webdriver右键菜单,发现selenium webdriver 无法操作浏览器右键菜单,如图 如果我想右键另存为 ...
- Selenium的PO模式(Page Object Model)|(Selenium Webdriver For Python)
研究Selenium + python 自动化测试有近两个月了,不能说非常熟练,起码对selenium自动化的执行有了深入的认识. 从最初无结构的代码,到类的使用,方法封装,从原始函数 ...
- Selenium WebDriver 之 PageObjects 模式 by Example
目录 1. 项目配置 2. 一个WebDriver简单例子 3. 使用Page Objects模式 4. 总结 5. Troubleshooting 6. 参考文档 本篇文章通过例子来阐述一下Sele ...
- Selenium WebDriver 处理cookie
在使用webdriver测试中,很多地方都使用登陆,cookie能够实现不必再次输入用户名密码进行登陆. 首先了解一下Java Cookie类的一些方法. 在jsp中处理cookie数据的常用方法: ...
随机推荐
- Codeforces Round #415 (Div. 2)C
反正又是一个半小时没做出来... 先排序,然后求和,第i个和第j个,f(a)=a[j]-a[i]=a[i]*(2^(j-i-1))因为从j到i之间有j-i-1个数(存在或者不存在有两种情况) 又有a[ ...
- 个人知识管理系统Version1.0开发记录(09)
MyBatis初试 MyBatis 是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索. 运用Mybatis框 ...
- 208. Implement Trie (Prefix Tree) -- 键树
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...
- IOS-网络(AFNetworking)
一.AFNetWorking基本使用 // // ViewController.m // IOS_0112_AFNetWorking // // Created by ma c on 16/2/11. ...
- Zynq软硬件协同设计 总结一
1.Xilinx在2012年推出了新一代的开发工具Vivado开发套件,目前的7系列FPGA既可以用以往的ISE或者XPS进行开发,也可以使用Vivado(为瓦度),而6系列等以前的产品智能使用ISE ...
- Nginx安装配置详解
http://nginx.org/download/ 下载对应的Nginx 安装nginx之前需要安装依赖包 yum install gcc gcc-c++ zlib-devel pcre-devel ...
- python实现八大排序算法
插入排序 核心思想 插入排序的基本操作就是将一个数据插入到已经排好序的有序数据中,从而得到一个新的.个数加一的有序数据,算法适用于少量数据的排序,时间复杂度为 O(n^2).是稳定的排序方法.插入算法 ...
- New Concept English Two 19 49
$课文47 嗜酒的鬼魂 481. A public house which was recently bought by Mr.Ian Thompson is up for sale. 伊恩.汤普森先 ...
- Java 异常Exception e中e的getMessage()和toString()方法的区别
示例代码1: public class TestInfo { private static String str =null; public static void main(String[] arg ...
- 关于数据库SQL语句的编写规范与tips
1. 插入数据时,建议使用如下B(指定字段名称赋值)的形式 A. update ${table} values('a','b','c;): B. update ${table} set (a,b,c) ...