2

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?

Niels van Reijmersdal
32.7k4 gold badges59 silver badges125 bronze badges
asked Apr 23, 2014 at 16:41

1 Answer 1

2

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(By.id("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.

Brandon
2021 silver badge4 bronze badges
answered May 5, 2014 at 18:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.