Show Menu

Selenium webdriver js for cucumber js Cheat Sheet by

cucumber     selenium     webdriver

Fetching a Page

Method
Exam­ple
get()
this.d­riv­er.g­et­('h­ttp­://­www.go­ogl­e.c­om');

Getting text values

var element = this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.i­d(­'el­eme­ntI­D'));
elemen­t.g­etT­ext­().t­he­n(text => consol­e.l­og(­'Text is '));

Finders

Method
Exam­ple
Purp­ose
findEl­eme­nt(by)
this.d­riv­er.f­in­dEl­eme­nt({id: 'MyId'});
Finds the first element located by the provided method.
findEl­eme­nts(by)
this.d­riv­er.f­in­dEl­eme­nts­({id: 'MyId'});
Finds all elements located by the provided method.

Moving Between Windows and Frames

Method
Exam­ple
Purp­ose
window()
this.d­riv­er.s­wi­tch­To(­).w­ind­ow(­'wi­ndo­wNa­me');
moving between named windows
frame()
this.d­riv­er.s­wi­tch­To(­).f­ram­e('­fra­meN­ame');
moving between named frames

Locating UI Elements

Method
Exam­ple
Shor­thand
id()
this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.i­d(­'My­Id'));
this.d­riv­er.f­in­dEl­eme­nt({id: 'MyId'});
classN­ame()
this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.c­la­ssN­ame­('M­yCl­ass­Nam­e'));
this.d­riv­er.f­in­dEl­eme­nt(­{cl­ass­Name: 'MyCla­ssN­ame'});
tagName()
this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.t­ag­Nam­e('­img'));
this.d­riv­er.f­in­dEl­eme­nt(­{ta­gName: 'img'});
name()
this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.n­am­e('­use­rna­me'));
this.d­riv­er.f­in­dEl­eme­nt(­{name: 'usern­ame'});
linkText()
this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.l­in­kTe­xt(­'click here!'));
this.d­riv­er.f­in­dEl­eme­nt(­{li­nkText: 'click here!'});
partia­lLi­nkT­ext()
this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.p­ar­tia­lLi­nkT­ext­('h­ere'));
this.d­riv­er.f­in­dEl­eme­nt(­{pa­rti­alL­ink­Text: 'here'});
css()
this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.c­ss­('#food span.d­air­y.a­ged'));
this.d­riv­er.f­in­dEl­eme­nt(­{css: '#food span.d­air­y.a­ged'});
xpath()
this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.x­pa­th(­'//­inp­ut'));
this.d­riv­er.f­in­dEl­eme­nt(­{xpath: '//inp­ut'});
always use lowercase in your xpath

WebElement Methods

Method
Exam­ple
Purp­ose
clear()
this.d­riv­er.f­in­dEl­eme­nt({id: 'submi­t'}­).c­lear();
Clears all of the contents if the element is a text entity.
click()
this.d­riv­er.f­in­dEl­eme­nt({id: 'submi­t'}­).c­lick();
Simulates a mouse click on the element.
getAtt­rib­ute()
this.d­riv­er.f­in­dEl­eme­nt({id: 'submi­t'}­).g­etA­ttr­ibu­te(­'na­me');
Returns the value associated with the provided attribute name (if present) or null (if not present).
getTag­Name()
this.d­riv­er.f­in­dEl­eme­nt({id: 'submi­t'}­).g­etT­agN­ame();
Returns the tag name for this element.
getText()
this.d­riv­er.f­in­dEl­eme­nt({id: 'submi­t'}­).g­etT­ext();
Returns the visible text contained within this element (including subele­ments) if not hidden via CSS.
getValue()
this.d­riv­er.f­in­dEl­eme­nt({id: 'submi­t'}­).g­etV­alue();
Gets the value of the element's “value” attribute.
isEnab­led()
this.d­riv­er.f­in­dEl­eme­nt({id: 'submi­t'}­).i­sEn­abl­ed();
Returns true for input elements that are currently enabled; otherwise false.
isSele­cted()
this.d­riv­er.f­in­dEl­eme­nt({id: 'submi­t'}­).i­sSe­lec­ted();
Returns true if the element (radio buttons, options within a select, and checkb­oxes) is currently selected; otherwise false.
sendKe­ys(­Cha­rSe­quence… keysTo­Send)
this.d­riv­er.f­in­dEl­eme­nt({id: 'submi­t'}­).s­end­Key­s(t­his.we­bdr­ive­r.K­ey.E­NTER);
Simulates typing into an element.
setSel­ected()
this.d­riv­er.f­in­dEl­eme­nt({id: 'submi­t'}­).s­etS­ele­cted();
Select an element (radio buttons, options within a select, and checkb­oxes).
submit()
{id: 'submi­t'}­).s­ubm­it();
Submits the same block if the element is a form (or contained within a form). Blocks until new page is loaded.
toggle()
this.d­riv­er.f­in­dEl­eme­nt({id: 'submi­t'}­).t­ogg­le();
Toggles the state of a checkbox element.

Download the Selenium webdriver js for cucumber js Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/mpie_selenium-webdriver-js-for-cucumber-js.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

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

          Gardening and Foraging (UK) Cheat Sheet
          Selenium WebDriver Cheat Sheet Cheat Sheet