0% found this document useful (0 votes)
30 views2 pages

Selenium CheatSheet

Uploaded by

Nanda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views2 pages

Selenium CheatSheet

Uploaded by

Nanda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SELENIUM LOCATORS SELENIUM NAVIGATORS

By.id() Navigate to url :


By.name() driver.get()
By.linkText() driver.navigate().to()
By.partialLinkText() Refresh page :
By.tagName() driver.navigate().refresh()
By.className() Navigate forwards in browser history :
By.xPath() driver.navigate().forward()
By.cssSelector()
Navigate backward in browser history :
driver.navigate().back()

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

getWindowHandle() - String is a return type click()


getWindowHandles() - Returns Set<String> clickAndHold()
driver.switchTo().window(windowHandle) contextClick()
driver.close() doubleClick()
driver.quit() dragAndDrop(source, target))
dragAndDropBy(source, xoffset,
Exception: y-ffset)
NoSuchWindowException - When the window moveToElement(toElement)
handle does not exist moveByOffset(x-offset, y-offset)
release()

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));

IMPLICIT WAIT VS EXPLICIT WAIT

IMPLICIT WAIT EXPLICIT WAIT


This wait can be considered as element This wait can be considered as conditional wait,
detection timeout. Once defined in a script, and is applied to a particular Web Element with
this wait will be set for all the Web Elements a condition
on a page.
Selenium keeps polling to check whether that WebDriverWait wait = new WebDriver
element is available to interact with or not. Wait(Driver, 90);
driver.manage().timeouts().implicitly
Wait(90, TimeUnit.SECONDS);

FINDEL EMENT VS FINDEL EMENTS

FINDEL EMENT FINDEL EMENTS


Returns a single WebElement Does not throw any exception
Returns an Empty List of WebElement Object
Syntax: WebElement findElement (By.locator())
Syntax: java.util.List<WebElement>
Exception: findElements(By.locator())
NoSuchElementException
Exception:
EmptyListofWebElementObject

You might also like