您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium獲取html的表格單元格數(shù)據(jù)
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2015/12/18 11:16:42 ] 推薦標(biāo)簽:功能測試工具 單元測試工具

  獲取網(wǎng)頁的表格的某個(gè)單元格的值,直接上代碼如下:
package com.table;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
/**
* @ClassName: TestTable
* @Description: TODO(獲取表格的某個(gè)單元格的值)
* @author qiaojiafei
* @date 2015年12月4日 上午10:32:44
*
*/
public class TestTable {
WebDriver dr = null;
public void init() {
System.setProperty("webdriver.chrome.bin", "D:/BaiduYunDownload/selenium/chromedriver.exe");
dr = new ChromeDriver();
dr.get("file:///D:/testhtml/table.html");
}
public void tearDown() {
dr.quit();
}
public List<WebElement> getRow() {
WebElement e_table = dr.findElement(By.id("myTable"));
List<WebElement> e_row = e_table.findElements(By.tagName("tr"));
int i = e_row.size();
//System.out.println(i);
return e_row;
}
public WebElement getCell(List<WebElement> list, int rowN, int colN) {
List<WebElement> e_col = list.get(rowN-1).findElements(By.tagName("td"));
return e_col.get(colN-1);
}
public String getTalbeValue(int rowN, int colN) {
String s = getCell(getRow(), rowN, colN).getText();
return s;
}
public static void main(String args[]) {
TestTable tt = new TestTable();
tt.init();
System.out.println(tt.getTalbeValue(2, 1));
}
}

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd