Selenium CheatSheet
Selenium CheatSheet
DROP DOWN
GET METHODS IN SELENIUM
selectByindex(int index)
selectByVisibleText(String text) getTitle() :
selectByValue(String value) to retrieve the current title of the webpage
getCurrentUrl() :
to retrieve the current URL of the webpage
ELEMENT VALIDATION getPageSource() :
to retrieve the current page source of the
Returns boolean value webpage
isEnabled() getText() :
isDisplayed() to retrieve the text of the specified web
isSelected() element
getAttribute() :
to retrieve the value specified in the
HANDLE ALERTS attribute
driver.switchTo().alert().getText()
driver.switchTo().alert().accept() FRAMES
driver.switchTo().alert().dismiss()
driver.switchTo().alert().sendKeys()
driver.switchTo().frame(int frameNumber)
driver.switchTo().frame(String frameNameOrID)
Exceptions:
driver.switchTo().frame(WebElement element)
NoAlertPresentException - You
driver.switchTo().defaultContent()
did not expect an alert, so are not
driver.switchTo.ParentFrame()
switch to it but you are working
on the main page even before Exceptions:
handling the alert. NoSuchFrameException - When no frame of
UnhandledAlertException - You (index/name/id) found
did not expect an alert, so did not NoSuchElementException - When using frame
switch but alert appeared as WebElement to switch
unexpectedly
WINDOW HANDLING MOUSE ACTIONS
TAKE SCREENSHOT
KEYBOARD ACTIONS
A Screenshot in Selenium Webdriver is used
for bug analysis. sendKeys()
Syntax: keyUp()
File src = driver.getScreenshotAs keyDown()
(OutputType.FILE);
FileUtils.copyFile(scr, new File(path));