Top Selenium Commands Cheat Sheet

Fetching a web page
Using Get method:
driver.get(“www.google.com”)

Using Navigate method:
driver.navigate().to(“https://google.com “);

Locating forms and sending user inputs
driver.findElement(By.id(“lst-ib”)).sendKeys(“selenium tutorials”);

Clearing User inputs
driver.findElement(By.name(“q”)).clear();

Fetching data over any web element
driver.findElement(By.id(“element567”)).getText();

Performing Click event
driver.findElement(By.id(“btnK”)).click();

Navigating backward in browser history
driver.navigate().back();

Navigating forward in browser history
driver.navigate().forward();

Refresh/ Reload a web page
driver.navigate().refresh();

Closing Browser
driver.close();

Closing Browser and other all other windows associated with
the driver
driver.quit();

Moving between Windows
driver.switchTo().window(“windowName”);

Moving between Frames
driver.switchTo().frame(“frameName”);

Drag and Drop
WebElement element = driver.findElement(By.name(“source”));
WebElement target = driver.findElement(By.name(“target”));
(new Actions(driver)).dragAndDrop(element, target).perform();