Show Menu
Cheatography

Selenium Cheat Sheet (DRAFT) by

Selenium Commands

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Invoke browsers on Windows OS

Firefox
WebDriver driver = new firefoxdriver();
//Selenium 3.0, beta 2 version
System.setProperty("webdriver.firefox.marionette", "./geckodriver.exe");
//Selenium 3.0, beta 1 version
System.setProperty("webdriver.gecko.driver", "./g­eck­odr­ive­r.e­xe");
Chrome
System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
WebDriver driver = new chrome­dri­ver();
IE
File file = new File("./IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new Intern­etE­xpl­ore­rDr­iver();

Select or DropDown element

Select select = new Select­(dr­ive­r.f­ind­Ele­ment(By locators));
Select multiple option from a list box
selectelement.sendkeys(keys.CONTROL)
selectelement.selectByVisibleText(1)
selectelement.selectByVisibleText(2)
List<W­ebE­lem­ent> dropdown=month.getOptions();
for(int i=0;i<­dro­pdo­wn.s­iz­e()­;i++){ String drop_d­own­_va­lue­s=d­rop­dow­n.g­et(­i).g­et­Text(); System.ou­t.p­rin­tln­("dr­opdown values are "­+dr­op_­dow­n_v­alues); }
 

Wait commands

Hard wait
Thread.sleep([time in milise­cond]);
Implicit Wait
driver.manage.timeouts().implicitlyWait(10,TimeUnit.SECONDS);
Explicit Wait
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditons.elementToBeClickable(By locators);
Fluent wait
WebElement element = fluent­Wait(By locators);
public WebElement fluent­Wait(By locator) {
Wait<webdriver> wait = new FluentWait<webdriver>(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
WebElement foo = wait.until(
new Functi­on<­web­driver webele­men­t="">() {
public WebElement apply(­Web­Driver driver) {
return driver.findElement(locator);
}
}
);
return foo;
};