Monday, February 14, 2011

Webdriver cheat sheet

▪ Core Classes
WebDriver
WebElement
By

▪ Visit page
webdriver.get(”url”)

▪ get page title, page source string
webdriver.getTitle(), getPageSource()

▪ Find Element(s)
WebElement elm = webdriver.findElement(s)(By byclause)

▪ By selector where selector in { name, id, tagname, name, xpath, cssName, cssSelector }
webdriver.findElement(By.(”selectorString”))

▪ Get text from a node
webElement.getText()

▪ Fill in input boxes
webElement.sendKeys(”value”)

▪ Click input buttons (radio, checkbox, submit, image)
webElement.click()

▪ Select option
webElement.setSelected()

▪ Submit form
webElement.submit()

▪ Waiting for a condition (ajax + dhtml)

ExpectedCondition cond = new ExpectedCondition() {
@Override
public Boolean apply(WebDriver arg0) { }
};
WebDriverWait wait = new WebDriverWait(driver, waitTime);
wait.until(cond);

▪ Configure implicit wait timeouts

driver.manage().timeouts().implicitlyWait(waitTime, TimeUnit.SECONDS);