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数据的常用方法: ...
随机推荐
- Rails 5 Test Prescriptions(everday Rspectest作者推荐) 目录 1-3章
总文档连接: RSpec.info/documentation/ 如何使用TDD 和 自动化测试来建立一个Rails app. TDD让你用测试来探索代码的设计.你将学习可利用的工具,并学习用什么工具 ...
- 020PHP基础知识——函数(三)
<?php /** * 任何数量的参数: * func_get_args() 接收一个数组,数组里面包含所有参数 * func_num_args() 取得共有几个参数 * func_get_ar ...
- PostgresException: 42883: function ifnull(integer, integer) does not exist
原因在于PostGresql并没有自带IFNULL函数,可以用COALESCE来替代IFNULL,且COALESCE功能更强大,可以输入更多参数,顺序判断并返回第一个非null值. 例如: SELEC ...
- BootStrap使用
BootStrap简单使用 <深入理解BootStrap>这本书对BootStrap进行了全面的讲解包括设计思想以及源码解析对没有接触过的很有帮助 BootStrap可以说是最简单的一类框 ...
- ZetCode PyQt4 tutorial custom widget
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- soql取第一件数据
User u = [select ID,Name from User Limit 1];
- HBase的几个实示例(二)
1 开发环境 在进行Hbase开发前,需要安装JDK.Hadoop和Hbase,选择一款合适的开发IDE,具体安装方法就不介绍了,我的开发环境: 操作系统:Ubuntu Java版本:jdk1.8 H ...
- cratedb 集群 docker-compose 安装试用
关于集群的配置说明可以参考官方文档,或者es 文档 详细代码参考 https://github.com/rongfengliang/cratedb-cluster-docker 参考配置 docker ...
- HP-Mercury SiteScope安装及监控Weblogic操作
1.Mercury SiteScope简介Mercury SiteScope是一款无代理监测解决方案,可确保分布式IT基础架构——如服务器.操作系统.网络设备.网络服务.应用和应用组件的可用性和性能. ...
- 1.Appium环境搭建
1.安装node.js (1)去node官网下载,根据操作系统的不同选择不同对应的版本(https://nodejs.org/en/download/) (2)下载对应的版本后进行安装,一直下一步直至 ...