Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

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.