Selenium webdriver js for cucumber js Cheat Sheet

A cheat sheet in English by mpie
31,631 views 4,376 downloads 25 Jul 2016 History
3.7 avg · 0 ratings

Fetching a Page

Method
Example
get()
this.d­riv­er.g­et­('ht­tp:­//w­ww.g­oo­gle.co­m');

Getting text values

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

Finders

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

Moving Between Windows and Frames

Method
Example
Purpose
window()
this.d­riv­er.s­wi­tch­To(­).w­ind­ow(­'­win­dow­Nam­e');
moving between named windows
frame()
this.d­riv­er.s­wi­tch­To(­).f­ram­e('f­ram­eNa­me');
moving between named frames

Locating UI Elements

Method
Example
Shorthand
id()
this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.i­d(­'­MyI­d'));
this.d­riv­er.f­in­dEl­eme­nt({id: '­MyI­d'});
classN­ame()
this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.c­la­ssN­ame­('My­Cla­ssN­ame­'));
this.d­riv­er.f­in­dEl­eme­nt(­{cl­ass­Name: '­MyC­las­sNa­me'});
tagName()
this.d­riv­er.f­in­dEl­eme­nt(­thi­s.d­riv­er.B­y.t­ag­Nam­e('i­mg'));
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('u­ser­nam­e'));
this.d­riv­er.f­in­dEl­eme­nt(­{name: '­use­rna­me'});
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­('he­re'));
this.d­riv­er.f­in­dEl­eme­nt(­{pa­rti­alL­ink­Text: '­her­e'});
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(­'­//i­npu­t'));
this.d­riv­er.f­in­dEl­eme­nt(­{xpath: '­//i­npu­t'});
always use lowercase in your xpath

WebElement Methods

Method
Example
Purpose
clear()
this.d­riv­er.f­in­dEl­eme­nt({id: '­sub­mit­'­}).c­le­ar();
Clears all of the contents if the element is a text entity.
click()
this.d­riv­er.f­in­dEl­eme­nt({id: '­sub­mit­'­}).c­li­ck();
Simulates a mouse click on the element.
getAtt­rib­ute()
this.d­riv­er.f­in­dEl­eme­nt({id: '­sub­mit­'­}).g­et­Att­rib­ute­('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: '­sub­mit­'­}).g­et­Tag­Name();
Returns the tag name for this element.
getText()
this.d­riv­er.f­in­dEl­eme­nt({id: '­sub­mit­'­}).g­et­Text();
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: '­sub­mit­'­}).g­et­Val­ue();
Gets the value of the elemen­t's “value” attribute.
isEnab­led()
this.d­riv­er.f­in­dEl­eme­nt({id: '­sub­mit­'­}).i­sE­nab­led();
Returns true for input elements that are currently enabled; otherwise false.
isSele­cted()
this.d­riv­er.f­in­dEl­eme­nt({id: '­sub­mit­'­}).i­sS­ele­cted();
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: '­sub­mit­'­}).s­en­dKe­ys(­thi­s.w­ebd­riv­er.K­ey.EN­TER);
Simulates typing into an element.
setSel­ected()
this.d­riv­er.f­in­dEl­eme­nt({id: '­sub­mit­'­}).s­et­Sel­ect­ed();
Select an element (radio buttons, options within a select, and checkb­oxes).
submit()
{id: '­sub­mit­'­}).s­ub­mit();
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: '­sub­mit­'­}).t­og­gle();
Toggles the state of a checkbox element.

Badges

Useful Cheat Sheet Nice Cheat Sheet Good Cheat Sheet Downloaded from Unusual Locations × 1

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.