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", "./geckodriver.exe"); |
Chrome |
System.setProperty("webdriver.chrome.driver","./chromedriver.exe"); WebDriver driver = new chromedriver(); |
IE |
File file = new File("./IEDriverServer.exe"); System.setProperty("webdriver.ie.driver", file.getAbsolutePath()); WebDriver driver = new InternetExplorerDriver(); |
Select or DropDown element
Select select = new Select(driver.findElement(By locators));
|
Select multiple option from a list box selectelement.sendkeys(keys.CONTROL) selectelement.selectByVisibleText(1) selectelement.selectByVisibleText(2) |
List<WebElement> dropdown=month.getOptions(); for(int i=0;i<dropdown.size();i++){ String drop_down_values=dropdown.get(i).getText(); System.out.println("dropdown values are "+drop_down_values); } |
|
|
Wait commands
Hard wait Thread.sleep([time in milisecond]); |
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 = fluentWait(By locators); public WebElement fluentWait(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 Function<webdriver webelement="">() { public WebElement apply(WebDriver driver) { return driver.findElement(locator); } } ); return foo; }; |
|