Selenium Cheat Sheet
Selenium Cheat Sheet
visibility
Get text
Get attribue
Get the select element
Get all the options for this element
Delete cookies By name
Delete All cookie
Java Script Dialouge handle javascript dialog
Select the options
Checkbox/Radio Check if it is selected
Select the element
Deselect the element
Wait/Sleep Implicit Wait:
Explicit Wait:
Sleep :
wait for a specific element to show up
wait 10 seconds until the element appear
Locators: Locating by ID
Locating by Name
Locating by Xpath
Locating Hyperlinksby Link Text
Locating by DOM
Locating by CSS
Locating by ClassName
Locating by TagName
Locating by LinkText
Locating by PartialLinkText
JUNIT annotations: @Test: test method to run with public void return type
@After: method to run after test method
@AfterClass: method to run before test method
@Before: method to run before test method
@BeforeClass: method to run once before any of the test methods in the class have b
@Ignore: This annotation is used to ignore a method
TestNG annotations: @test: This annotation marks a class or method as a part of a test
@BeforeSuite: This annotation makes sure that the method only run once before all t
@AfterSuite: This annotation makes sure that the method runs once after the executio
@BeforeTest: This annotation will make sure that the method marked with this anno
@AfterTest: This annotation will make sure that the method marked with this annota
@BeforeGroups : A method annotated with this annotation will run before all the firs
@AfterGroups: A method annotated with this annotation will run after all the test me
@BeforeClass: A method annotated with this annotation will run only once per class
@AfterClass: A method annotated with this annotation will run only once per class a
@BeforeMethod: A method annotated with this annotation will run before every @te
@AfterMethod: A method annotated with this annotation will run after every @test a
Command
Firefox WebDriver driver = new FirefoxDriver();
Chrome WebDriver driver = new ChromeDriver();
Safari Driver WebDriver driver = new InternetExplorerDriver();
Internet Explorer WebDriver driver = new SafariDriver();
get("www.webdriverinselenium.com");
findElement(By.id("submit")).click();
getElementsByName('') [0].setAttribute('disabled', '')
getElementsByName('') [0].removeAttribute('disabled');
File snapshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(snapshot, new File("C:\\scre
String pagetitle = driver.getTitle(); System.out.print(pagetitle);
driver.find_element(:id, 'TextArea').send_keys 'InputText'
driver.find_element(:id,'Element').displayed?
driver.find_element(:id,'Element').text
driver.find_element(:id, 'Element').attribute('class')
select = driver.find_element(:tag_name, "select")
all_options = select.find_elements(:tag_name, "option")
driver.manage.delete_cookie("CookieName")
driver.manage.delete_all_cookies
a.dismiss
puts
else "Value is: " + option.attribute("value")
option.click
end
driver.find_element(:id, 'CheckBox').selected?
driver.find_element(:id, 'CheckBox').click
driver.find_element(:id, 'CheckBox').clear
manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 20);
Thread.Sleep(10);
wait = Selenium::WebDriver::Wait.new(:timeout => 10) (set the timeout to 10 seconds)
wait.until { driver.find_element(:id => "foo") }
driver.get(“http://newexample.com”); driver.navigate().to(“http://newexample.com”)
driver.navigate().refresh()
driver.navigate().forward()
driver.navigate().back()
String curWindow=driver.getWindowHandle();
Set<String> handles = getWindowHandles(); For(string handle: handles) {If (!handle.equals(curWindow)) {driver.switchTo().w
}
}
driver.switchTO().frame(1);
driver.switchTo().frame(“name”)
driver.switchTO().frame(element);
driver.switchTO().defaultContent();
driver.switchTO().alert.getText();
driver.switchTO().alert.accept();
driver.switchTO().alert.dismiss();
driver.switchTO().alert.sendKeys(“Text”)