Thursday, March 31, 2011

Get total number of rows from a HtmlTable - Webdriver

Below code can be used to get rowcount from a Html table. If table not exists returns -1.

private int getRowCount(By by) throws Exception {
        try {
            WebElement table = driver.findElement(by);
            List rows = table.findElements(By.tagName("tr"));
            return rows.size();
        } catch (Exception e) {
            return -1;
        }

    }

No comments: