You are on page 1of 1

Selenium WebDriver Cheat Sheet

by Rajesh (rajeshcdp) via cheatography.com/33195/cs/10324/


Locators

Browser Commands

RadioButton

ID

Get command

isSelected

Name

Get Title Command

Link Text

Get current Url Command

CSS Selector - Tag and ID, Tag and Class, Tag

Get Page Source Command

To Command

Refresh Command

and Attribute, Tag ID Class and Attribute , Inner

Close Command

Back Command

Forward Command

Text

Browser Navigation Commands

Quit Command

DOM - GetElementById,
GetElementByName,dom:name,dom:index
XPATH

Switch Commands

Refresh Command

driver.switchTo.window("WindowName")
driver.switchTo.frame("FrameName")

testNG Annotations

Implicit Wait Vs Explicit Wait Vs Fluent Wait

@Test

@Before

@AferM

@BeforeCl

Method

ethod

ass

@Before

@AfterGr

@Before

@AfterTest

Group

oup

Test

@AfterSuite

This wait can be

This wait can be

considered as element

considered as

detection timeout. Once

conditional wait,

defined in a script, this

and is applied to a

@Before

wait will be set for all the

particular Web

Suite

Web Elements on a

Element with a

page.

condition

Selenium keeps polling

WebDriverWait

to check whether that

wait = new

element is available to

WebDriverWait(Dri

interact with or not.

not Selected

driver.SwitchTo.alert()
CheckBox
Checked

not Checked

Difference between '/' and '//'

Web Element Commands

Single Slah '/' -> Look for the element


immediately inside its parent element

Elements can be found by using

Eg : Absolute path

By Id

:/html/body/form/div/div[3]/[p1]/a

ver, 90);

By Name

Double Slah '//' -> Look for any child or grand

Driver.manage().timeouts

wait.until(Expected

By Class Name

().implicitlyWait(90,

Conditions.visibility

TimeUnit.SECONDS);

OfElementsLocated

By Tag Name

By(By.xpath("//input[
@type='text']")));

child inside parent element


eg: Releative path ://*[@id:loginform][p1]/a

By Link Text

DropDown

By Partial Link Text

Fluent Wait you have an element which

By CSS

sometime appears in just 1 second and some

By Xpath

selectByVisibleText

selectByIndex

selectByValue

time it takes minutes to appear. In that case it is


better to use fluent wait, as this will try to find
element again and again until it find it or until
the final timer runs out.

findElement Vs findElements
Returns a single

Returns List of

WebElement

WebElements.

Syntax:

Syntax:

WebElement

java.util.List<WebElement

findElement(By

> findElements(By by)

by)
Exception

Exception:emptyListofWeb

:NoSuchElementE

ElementObject

xception
By Rajesh (rajeshcdp)

Published 26th December, 2016.

Sponsored by CrosswordCheats.com

cheatography.com/rajeshcdp/

Last updated 26th December, 2016.

Learn to solve cryptic crosswords!

Page 1 of 1.

http://crosswordcheats.com

You might also like