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数据的常用方法: ...
随机推荐
- windows下的IO模型之事件选择(WSAEventSelect)模型
异步选择模型类似的是,它也允许应用程序在一个或多个套接字上,接收以事件为基础的网络事件通知.对于异步选择模型采用的网络事件来说,它们均可原封不动地移植到事件选择模型.事件选择模型和异步选择模型最主要的 ...
- IOS-高仿bilibili项目
高仿bilibili项目成长之路 (logo) 高仿bilibili项目 Github链接:(https://github.com/MichaelHuyp/Bilibili_Wuxianda) 目前完 ...
- springboot模糊查询
在学习MyBatis过程中想实现模糊查询,可惜失败了.后来上百度上查了一下,算是解决了.记录一下MyBatis实现模糊查询的几种方式. 数据库表名为test_student,初始化了几条记录,如图: ...
- hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分 圆相交面积 难度:1
Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...
- activity+fragment+listview+adapter+bean在同一个类中的套路
1.xml activity_main.xml <?xml version="1.0" encoding="utf-8"?><FrameLay ...
- vuex: 简单(弹窗)实现
在使用基于 vue.js 2.0 的UI框架 ElementUI 开发网站的时候 , 就遇到了这种问题 : 一个页面有很多表单 , 我试图将表单写成一个单文件组件 , 但是表单 ( 子组件 ) 里的数 ...
- 记录一些js框架用途
accounting.min.js 货币格式化alertify.min.js 提示信息库amd.loader.js 按需动态加载js文件angular-cookies.js 处理cookieangul ...
- python3高阶函数:map(),reduce(),filter()的区别
转载请注明出处:https://www.cnblogs.com/shapeL/p/9057152.html 1.map():遍历序列,对序列中每个元素进行操作,最终获取新的序列 print(list( ...
- ionic2中跨页面回传值
1.在跳转到新页面时传入一个contactsCallback的参数,在该参数的函数定义中做出一个承诺. 注意:最开始我本来是采用如下图方式的,但是很不幸,出现了问题,问题所在就是关于这个this的作用 ...
- linux vi常用操作
1.基本操作 进入vi vi 或者 vim 进入一个文件或者新建一个文件 例如:vim 11.txt vi有3种模式 一般模式:刚进入时.按esc时. 编辑模式:按下字母[i, I, o, O, a, ...