Reputation: 299
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
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