0% found this document useful (0 votes)
459 views

Selenium Web Driver Cheat Sheet

The document provides a cheat sheet on Selenium WebDriver with sections on driver initialization for Firefox, Chrome, and Internet Explorer; locating elements using different locators like ID, name, XPath; handling alerts and waits; taking screenshots; and examples of practice scripts for common automation tasks like clicking buttons and entering text. It also includes annotations for TestNG and JUnit and tips for exceptions and best practices.

Uploaded by

mohangbox
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
459 views

Selenium Web Driver Cheat Sheet

The document provides a cheat sheet on Selenium WebDriver with sections on driver initialization for Firefox, Chrome, and Internet Explorer; locating elements using different locators like ID, name, XPath; handling alerts and waits; taking screenshots; and examples of practice scripts for common automation tasks like clicking buttons and entering text. It also includes annotations for TestNG and JUnit and tips for exceptions and best practices.

Uploaded by

mohangbox
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SELENIUM WEBDRIVER

SELENIUM WEBDRIVER CHEATSHEET


Selenium WebDriver Cheat CHEATSHEET
Sheet Cheat Sheet
by Narayanan Palani (Narayanan Palani) via cheatography.com/32112/cs/9838/

Driver Initia​liz​ation Selenium Locators (cont)

Fire​fox (Below v.47)​ Refer System.se​tPr​ope​rty​("we​bdr​ive​r.g​eck​o.d​riv​ Locating by DOM​Refer dom


Part2-​Page58 er", "​Pat​hTo​\\g​eck​odr​ive​r.e​xe"); Part2-​Page39 =docum​ent.ge​tEl​eme​ntB​yId​('s​ign​inF​orm')

Download from WebDriver driver = new Firefo​xDr​iver(); Locating by CSS​Refer driver.Fi​ndE​lem​ent​(By.Cs​sSe​lec​tor​("#r​ightbar


https:​//g​ith​ub.c​om​/mo​zil​la/​gec​ko Part2-​Pag​e40-43 > .menu > li:nth​-of​-ty​pe(2) > h4"));
d​riv​er/​rel​eases
Locating by driver.fi​ndE​lem​ent​(By.cl​ass​Nam​e("p​rof​ile​-
Chro​me Refer
​ Part2-​Page59 System.se​tPr​ope​rty​("We​bDr​ive​r.c​hro​me. ClassN​ame​​Refer he​ade​r"));
d​ri​ver​", Part2-​Page37
System.ge​tPr​ope​rty​("us​er.d​ir​"​)+"/​/Br​ows​e
Locating by driver.fi​ndE​lem​ent​(By.ta​gNa​me(​"​sel​ect​"​)).C​li​
rD​riv​ers​//c​hro​med​riv​er.e​xe​");
TagNam​eRefer
​ ck();
Download from WebDriver driver = new
Part2-​Page37
https:​//s​ite​s.g​oog​le.c​om​/a/​chr​om Chrome​Dri​ver();
i​um.o​rg​/ch​rom​edr​ive​r/d​own​load Locating by driver.fi​ndE​lem​ent​(By.li​nkT​ext​("Ne​xtP​age​"​)).c​
s LinkTe​xt​Refer li​ck();
Part2-​Pag​e37-40
Internet Explor​er​Refer System.se​tPr​ope​rty​("We​bDr​ive​r.i​e.d​riv​er"
Part2-​Page59 , "​Pat​hTo​//I​EDr​ive​rSe​rve​r.e​xe"); Locating by driver.fi​ndE​lem​ent​(By.pa​rti​alL​ink​Tex​t("N​ext​P"
Partia​lLi​nkT​ext​​Refer )).cl​ick();
Download from The Internet WebDriver driver = new
Part2-​Pag​e37-40
Explorer Driver Server at Intern​etE​xpl​ore​rDr​iver();
http:/​/do​cs.s​el​eni​umh​q.o​rg/​dow​n
load/ Selenium Exceptions

'Server Exception : sessionId should not Replace Chrome Driver


Selenium Locators
be null​Refer Part2-​Pag​e160 with Latest Version
Locating by ID Refer driver.fi​ndE​lem​ent​(By.id​("q")​).s​end​Key​s("
ERROR: No sessionId provid​ed​Refer Use Jenkins
Part2-​Page37 S​elenium 3"); Part2-​Pag​e160

Locating by Name​Refer driver.fi​ndE​lem​ent​(By.na​me(​"​q")).se​ndK​e


Unre​ach​abl​eBr​ows​erE​xce​pti​on Refer
​ Registry Key Changes
Part2-​Page37 ys​("Se​lenium 3"); Part2-​Pag​e160 Recomm​ended
Locating by Xpath​Refer driver.fi​ndE​lem​ent​(By.xp​ath​("//​inp​ut[​@id​='
Illegal state exception using Selenium Get latest Firefox Gecko
Part2-​Pag​e37/38 q​']")​).s​end​Key​s("S​elenium 3");
3Refer Part2-​Pag​e161 Driver
Locating Hyperlinks by Link driver.Fi​ndE​lem​ent​(By.Li​nkT​ext​("edit
Text Refer Part2-​Pag​e38/39 this page")).Cl​ick(); Selenium
Annota​tions Practice Scripts (cont)

TestNG @Befor​eSuite @After​Suite @Befor​eTest @AfterTest Disable a driver.ge​tEl​eme​nts​ByN​ame​('<​Obj​ect​ID>​')


@Befor​eGroups @After​Groups @Befor​eClass @After​Class Field​Refer [​0].s​et​Att​rib​ute​('d​isa​bled', '');
@Befor​eMethod @After​Method Part2-​Page64

JUnit @After @After​Class @Before @Befor​eClass @Ignore @Test Enable a driver.ge​tEl​eme​nts​ByN​ame​('<​Obj​ect​ID>​')


Field​Refer [​0].r​em​ove​Att​rib​ute​('d​isa​bled';
Author​:Na​rayanan Palani Part2-​Page64

Scre​ens​hot​​Ref File snapshot =


er Part2-​Page64 ((Take​sSc​ree​nsh​ot)​dri​ver​).g​etS​cre​ens​hot​As(​Out​put​Typ​e
.F​ILE);

FileUt​ils.co​pyF​ile​(sn​apshot, new
File("C​:\​\scr​een​sho​t.j​pg"));

Print the Title String pagetitle = driver.ge​tTi​tle();


of the
Page​Refer
Part2-​Page68
Practice Scripts
System.ou​t.p​rin​t(p​age​title);
Launch driver.ge​t("w​ww.r​ag​hav​a.u​k");
Implicit driver.ma​nag​e().ti​meo​uts​().i​mp​lic​itl​yWa​it(10,
Webpag​eRefer

Wait​Refer TimeUn​it.S​EC​ONDS);
Part2-​Page60
Part2-​Page69
Click driver.fi​ndE​lem​ent​(By.id​("su​bmi​t")).cl​ick();
Explicit WebDri​verWait wait = new WebDri​ver​Wai​t(d​river, 20);
Button​ ​Refer
Part2-​Page60
Wait​Refer
Part2-​Page70
Store Text​Refer String txtDro​pdown =
wait.u​nti​l(E​xpe​cte​dCo​ndi​tio​ns.t​ex​tTo​BeP​res​ent​InE​lem​ent​
Part2-​Page60 driver.fi​ndE​lem​ent​(By.ID​("se​lec​t")).ge​tTe​xt();
Loc​ate​d(B​y.x​pat​h("/​/di​v[@​id=​'<O​bject ID>​']"), "​Enter
Enter Text​Refer driver.fi​ndE​lem​ent​(By.xp​ath​("//​inp​ut[​@na​me=​'Fi​rst​Na Your Personal Detail​s"));
Part2-​Page61 m​e03​4']​"​)).s​en​dKe​ys(​"​Nar​aya​nan​Pal​ani​");
Fluent Wait wait = new Fluent​Wai​t(d​river)
Handle Alert​Refer Alert Alertpopup = driver.sw​itc​hTo​().a​le​rt(); Wait​Refer
Part2-​Page62 Part2-​Page70

(Mou​se)​Cli​ck​Ref driver.fi​ndE​lem​ent​(By.xp​ath​("//​inp​ut[​@va​lue​='O​BJECT .withT​ime​out(20, SECONDS)


er Part2-​Page62 NAME']​"​)).c​li​ck();
Slee​pRefer
​ Thread.Sl​eep​(10);
Compare Assert.as​ser​tTr​ue(​chk​box​12.i​sS​ele​cte​d()); Part2-​Page70

Text​Refer
Part2-​Page64

By Narayanan Palani Published 15th November, 2016. Sponsored by Readability-Score.com


Selenium Automation Framework using Java Software Automation Testing Secrets Revealed

Java​ ​Refer Part1-​Page74 http:/​/ww​w.o​rac​le.c​om​/te​chn​etw​ork​/ja​va/​j


av​ase​/do​wnl​oad​s/i​nde​x.html

Java Config​ura​tio​nRefer
​ JAVA_H​OME​,PATH
Part1-​Page75

Eclipse IDE​Refer Part1-​Page79 http:/​/ec​lip​se.o​rg​/do​wnl​oads/

Excel Data Driven http://


Capabi​lit​yRefer
​ Part1-​Page88 archiv​e.a​pac​he.o​rg​/di​st/​poi​/re​lea​se/bin/

Logging Capabi​lit​y- http:/​/lo​ggi​ng.a​pa​che.or​g/l​og4​j/1.2/​dow​nlo​


L​og4​J Refer
​ Part1-​Page90 ad.html

Sele​niu​mRefer
​ Part1-​Page92 http:/​/do​cs.s​el​eni​umh​q.o​rg/​dow​nload/

HTML​/Email Report​ing​-XSLT http:/​/mv​nre​pos​ito​ry.c​om​/ar​tif​act​/ne​t.s​f.s​a


Report​ ​Refer Part1-​Page93 xo​n/s​axo​n/8.7

Ant Build Capabi​lit​yRefer


​ http:/​/an​t.a​pac​he.o​rg​/an​tli​bs/​bin​dow​nlo​ad.
Part1-​Page93 cgi

Mave​nRefer
​ Part1-​Pag​e126 http:/​/do​wnl​oad.ec​lip​se.o​rg​/te​chn​olo​gy/​m2
e​/re​leases

Test​NG-Test Execution http:/​/be​ust.co​m/e​clipse


Capabi​lit​yRefer
​ Part1-​Pag​e102

Cucu​mbe​rRefer
​ Part1-​Pag​e204 https:​//c​ucu​mbe​r.i​o/c​ucu​mbe​r- Seleni​umW​ebD​river
e​cli​pse​/up​dat​e-site

Cheat Sheet Book Reference

Software Automation https:​//w​ww.a​ma​zon.co​m/S​oft​war​e-


Testing Secrets Revealed A​uto​mat​ion​-Te​sti​ng-​Sec​ret​s-
R​eve​ale​d/d​p/9​383​952954/

Selenium WebDriver: https:​//w​ww.e​du​cre​ati​on.i​n/​sto​re/​sel​eni​um-​web​


Software Automation dri​ver​-so​ftw​are​-au​tom​ati​on-​tes​tin​g-s​ecr​ets​-
Testing Secrets Revealed re​vea​led​-pa​rt2​-na​ray​ana​n-p​ala​ni.html
Part 2

Software Automation Testing Secrets Revealed Part 2

You might also like