Show Menu
Cheatography

Selenium WebDriver Cheat Sheet by

Selenium Made Easy

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
 
                   
 

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

          Selenium WebDriver Cheat Sheet Cheat Sheet
          Cypressio Cheat Sheet
          ISTQB Test Automation Engineering Cheat Sheet