您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium WebDriver處理Table
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2014/12/4 14:14:35 ] 推薦標(biāo)簽:Selenium 軟件測試工具

  那么問題來了,我想通過xpath獲取這個(gè)table的每一個(gè)cell的值(比如獲取expect的值),該怎么做。
  如果這個(gè)表格被改變了,增加或刪除一些行列該如何處理?
  我的solution是獲取table的base xpath,這個(gè)所謂的base xpath是指這個(gè)table的第n行第m列相同的部分,然后通過傳入n,m獲取返回值
public static String tableCell(WebDriver driver,int row, int column)
{
String text = null;
//avoid get the head line of the table
row=row+1;
String xpath="//*[@id='table138']/tbody/tr["+row+"]/td["+column+"]";
WebElement table=driver.findElement(By.xpath(xpath)); //*[@id="table138"]/tbody/tr[1]/td[1]/strong
text=table.getText();
return text;
}
  所以,tableCell(driver,1,2)能返回

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