Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a DOM structure "div > table id = 't1' > tbody > tr" (count of tr changes on resize) The javascript function changes the number of rows on resizing the browser. I want to count number of rows for the table.

I am using the following code

   final String tablePath = "//../div/table[1]";
   final int size = Browser.getElements(By.xpath(tablePath).tagName("tbody")).size();
   System.out.println("row count=" + size);

How will I show the rowcount which is changing dynamically?

share|improve this question

The size() function returns the number of elements found with the getElements() function, I expect it to return just one table element. The value of size equals 1.

I would get the HTML inside the table and count the occurrences of <tr> or something unique per row, expecting you do not have nested tables with rows inside the initial table. The code for that would look something like this:

WebElement table = driver.findElement("t1"));
String tableContent = table.getAttribute("innerHTML");
int count = StringUtils.countMatches(tabelContent, "<tr>");

After you change the window size you will have to get the innerHTML again and count the rows to see if it actually changed or not.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.