Show Menu

Selenium WebDriver Cheat Sheet by

Selenium Made Easy
browser     selenium     testng     locators     webelement     findelement

Locators

ID
Name
Link Text
CSS Selector - Tag and ID, Tag and Class, Tag and Attribute, Tag ID Class and Attribute , Inner Text
DOM - GetEle­men­tById, GetEle­men­tBy­Nam­e,d­om:­nam­e,d­om:­index
XPATH

Implicit Wait Vs Explicit Wait Vs Fluent Wait

This wait can be considered as element detection timeout. Once defined in a script, this wait will be set for all the Web Elements on a page.
This wait can be considered as condit­ional wait, and is applied to a particular Web Element with a condition
Selenium keeps polling to check whether that element is available to interact with or not.
WebDri­verWait wait = new WebDri­ver­Wai­t(D­river, 90);
Driver.ma­nag­e().ti­meo­uts­().i­mp­lic­itl­yWa­it(90, TimeUn­it.S­EC­ONDS);
wait.u­nti­l(E­xpe­cte­dCo­ndi­tio­ns.v­is­ibi­lit­yOf­Ele­men­tsL­oca­ted­By(­By.x­pa­th(­"­//i­npu­t[@­typ­e='­tex­t']­")));
Fluent Wait you have an element which sometime appears in just 1 second and some 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.

Browser Commands

Get command
Get Title Command
Get current Url Command
Get Page Source Command
Close Command
Quit Command
Refresh Command

testNG Annota­tions

@Test
@Befor­eMethod
@AferM­ethod
@Befor­eClass
@Befor­eGroup
@After­Group
@Befor­eTest
@AfterTest
@Befor­eSuite
@After­Suite
 

Web Element Commands

Elements can be found by using
By Id
By Name
By Class Name
By Tag Name
By Link Text
By Partial Link Text
By CSS
By Xpath

findEl­ement Vs findEl­ements

Returns a single WebElement
Returns List of WebEle­ments.
Syntax: WebElement findEl­eme­nt(By by)
Syntax: java.u­til.Li­st<­Web­Ele­men­t> findEl­eme­nts(By by)
Exception :NoSuc­hEl­eme­ntE­xce­ption
Except­ion­:em­pty­Lis­tof­Web­Ele­men­tObject

RadioB­utton

isSelected
not Selected

Browser Navigation Commands

To Command
Refresh Command
Back Command
Forward Command

Switch Commands

driver.sw­itc­hTo.wi­ndo­w("W­ind­owN­ame­")
driver.sw­itc­hTo.fr­ame­("Fr­ame­Nam­e")
driver.Sw­itc­hTo.al­ert()

CheckBox

Checked
not Checked

Difference between '/' and '//'

Single Slah '/' -> Look for the element immedi­ately inside its parent element
Eg : Absolute path :/html­/bo­dy/­for­m/d­iv/­div­[3]­/[p1]/a
Double Slah '//' -> Look for any child or grand child inside parent element
eg: Releative path ://*[@­id:­log­inf­orm­][p1]/a

DropDown

select­ByV­isi­bleText
select­ByIndex
select­ByValue
 

Download the Selenium WebDriver Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/rajeshcdp_selenium-webdriver.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

Like this cheat sheet? Check out our sponsors!

Readable.io is a collection of tools to make your writing better. More readable content means higher conversion rates and better reader engagement. Measure website and document readability, measure keyword density and more!

Click Here To Get Started!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Firefox Cheat Sheet
          Selenium WebDriver Cheat Sheet Cheat Sheet