那么問(wèn)題來(lái)了,我想通過(guò)xpath獲取這個(gè)table的每一個(gè)cell的值(比如獲取expect的值),該怎么做。
如果這個(gè)表格被改變了,增加或刪除一些行列該如何處理?
我的solution是獲取table的base xpath,這個(gè)所謂的base xpath是指這個(gè)table的第n行第m列相同的部分,然后通過(guò)傳入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)能返回