Selenium Cheat Sheet-1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Selenium WebDriver Cheat Sheet

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

Locators Browser Commands RadioB​utton

ID Get command isSelected not Selected

Name Get Title Command


Browser Navigation Commands
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 Back Command Forward Command
Close Command
Text
Quit Command
DOM - GetEle​men​tById, Switch Commands
Refresh Command
GetEle​men​tBy​Nam​e,d​om:​nam​e,d​om:​index
driver.sw​itc​hTo.wi​ndo​w("W​ind​owN​ame​")
XPATH
testNG Annota​tions driver.sw​itc​hTo.fr​ame​("Fr​ame​Nam​e")

@Test @Befor​e @AferM​ @Befor​eCl driver.Sw​itc​hTo.al​ert()


Implicit Wait Vs Explicit Wait Vs Fluent Wait
Method ethod ass
This wait can be This wait can be CheckBox
@Befor​e @After​Gr @Befor​e @AfterTest
considered as element considered as
Group oup Test Checked not Checked
detection timeout. Once condit​ional wait,
defined in a script, this and is applied to a @Befor​e @After​Suite
wait will be set for all the particular Web Suite Difference between '/' and '//'
Web Elements on a Element with a
Single Slah '/' -> Look for the element
page. condition Web Element Commands
immedi​ately inside its parent element
Selenium keeps polling WebDri​verWait
Elements can be found by using Eg : Absolute path
to check whether that wait = new
By Id :/html​/bo​dy/​for​m/d​iv/​div​[3]​/[p1]/a
element is available to WebDri​ver​Wai​t(D​ri
interact with or not. ver, 90); By Name Double Slah '//' -> Look for any child or grand
child inside parent element
Driver.ma​nag​e().ti​meo​uts​ wait.u​nti​l(E​xpe​cte​d By Class Name
().i​mp​lic​itl​yWa​it(90, Co​ndi​tio​ns.v​is​ibi​lit​y eg: Releative path ://*[@​id:​log​inf​orm​][p1]/a
By Tag Name
TimeUn​it.S​EC​ONDS); Of​Ele​men​tsL​oca​ted​
By Link Text
By(​By.x​pa​th(​"​//i​npu​t[‐ DropDown
@​typ​e='​tex​t']​"))); By Partial Link Text
select​ByV​isi​bleText select​ByIndex
Fluent Wait you have an element which By CSS
select​ByValue
sometime appears in just 1 second and some By Xpath
time it takes minutes to appear. In that case it is
better to use fluent wait, as this will try to find findEl​ement Vs findEl​ements
element again and again until it find it or until
Returns a single Returns List of
the final timer runs out.
WebElement WebEle​ments.

Syntax: Syntax:
WebElement java.u​til.Li​st<​Web​Ele​men​t
findEl​eme​nt(By > findEl​eme​nts(By by)
by)

Exception Except​ion​:em​pty​Lis​tof​Web​
:NoSuc​hEl​eme​ntE​ Ele​men​tObject
xce​ption

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