Selenium – 如何计算表中的行数?

我有一个行数为“n”的表。 我需要数数,怎么办?

示例: – 我的表格如下所示。

Type Balance Date received Date returned Payment method Amount General Default 10/01/2013 08:53:20 Cash $ 10.00 HTML of my table looks like this.  is table title row and  are the entries done by the user. Everytime the user add the new entry, the count will increase and display a message "3 found for account 6478 ". where 3 is no of rows in the table. 

要将行数存储到表中,可以使用storeXpathCount

 storeXpathCount | id=listBalances | NumberOfRows echo | ${NumberOfRows} 

storeXpathCount将行计数存储到变量NumberOfRows中,echo将返回count。

我建议如下:

1)制作表格元素列表(例如,如果需要计算行数,则使用适当的选择器选择任何行)。

2)然后创建Web元素列表

 List columnElments = driver.findElements(By.cssSelector("...blablabla...")); int rowNumer = columnElmments.size(); 

或者:

 @FindBy (how = How.CSS, using = "blablablba") List col; int rowNumer =col.size(); 

希望你明白了

Type Balance Date received Date returned Payment method Amount
General Deposit Default for RTB 09/30/2013 06:58:41 Cash $ 5.00