Dashboard > Selenium > ... > Getting Started with Selenium Core > HowTo verify numbers of rows in a table
Selenium Log In View a printable version of the current page.
HowTo verify numbers of rows in a table
Added by alex, last edited by alex on Jun 22, 2006
Labels: 
(None)

One way to do it is to Assert that row n exists while  row n+1 does not exists with xpath, something like :
assertElementPresent | //table[@id='mytable']/tr[10] | |
assertElementNotPresent | //table[@id='mytable']/tr[11] | |
to verify table with id mytable does not have 10 elements

Another way is to use the SEL:storeassertXpath extension to count columns
assertXpath | count(//table[@id='mytable']/tr) | 10

Here i am using GetXpathCount() and xpath to identify the row collection of the named ("mytable") table.

Assert.AreEqual(3,selenium.GetXpathCount("xpath=id('mytable')/tbody/tr"),"Expected 3 rows in table");

Here i am asserting my table contains 3 rows (including heading)

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators