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;
        }

    }

Friday, March 18, 2011

Clear contents and input a value webdriver

public void inputValue(WebElement txtbox
 ,String value) throws Exception{ 
txtbox
.sendKeys(Keys.chord(Keys.CONTROL, "a"), value);
}