user2388556
user2388556

Reputation: 299

Count the number of rows with xpath but .size() is not available

I'm trying to count the number of rows in table and based on my research for webdriver, I should be using as code below. However, I am unable to see .size() method populated and i'll be appreciated if someone can explain to me?

int rowCount = driver.findElement(By.xpath("//*[@id='hitlist']/form/table/tbody/t")).size();

Thanks.

Upvotes: 1

Views: 5163

Answers (1)

Yi Zeng
Yi Zeng

Reputation: 32885

driver.findElement will only find one element, the return type is WebElement.

You want driver.findElements, which has return type of List<WebElement>. (Source here)

Use it like this:

int rowCount = driver.findElements(By.xpath("//*[@id='hitlist']/form/table/tbody/tr")).size();

Upvotes: 2

Related Questions