Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Protractor API Cheatsheet

Protractor API

Note: Most commands return promises, so you only resolve their values through using jasmine expect API or using .then(function()) structure

Based on this post: by @crystoll

Control browser

browser.get('yoururl'); // Load address, can also use '#yourpage'



browser.sleep(10000); // if your test is outrunning the browser

browser.waitForAngular(); // if your test is outrunning the browser

browser.getLocationAbsUrl() // get the current address

browser.ignoreSynchronization = true; // If true, Protractor will not attempt to synchronize with the page before performing actions


Here's a trick how to wait for something to become present/visible:

browser.wait(function() {
   return element('create')).isPresent();
}, 5000);

Check visibility

element('create')).isPresent() // Be careful with this: element is often present while it's not displayed...

element('create')).isEnabled() //Enabled/disabled, as in ng-disabled...

element('create')).isDisplayed() //Is element currently visible/displayed?

Find an element by id, model, binding, ...



element(by.model('')) // refers to ng-model directive

element(by.binding('person.concatName')); // refers to ng-bind directive


element (by.input( 'username' ));

element (by.input( 'username' )).clear();






var dog = element(by.cssContainingText('.pet', 'Dog'));

var allOptions = element.all(by.options('c c in colors')); //When ng-options is used with selectbox

Find collection of elements by css, repeater, xpath..

var list = element.all(by.css('.items));

var list2 = element.all(by.repeater('personhome.results'));

var list3 = element.all(by.xpath('//div






Send keystrokes, clear





Position and size, also how to deal with promises:

element('item1')).getLocation().then(function(location) {
  var x = location.x;
  var y = location.y;

element('item1')).getSize().then(function(size) {
  var width = size.width;
  var height = size.height;

Jasmine Matchers

to(N­ot)­Be( null | true | false )
to(N­ot)­Equ­al( value )
to(N­ot)­Mat­ch( regex | string )
to(N­ot)­Con­tain( string )
toBe­Les­sTh­an( number )
toBe­Gre­ate­rTh­an( number )
toBe­Clo­seTo( number, precision )
Copy link

rchovatiya88 commented Mar 15, 2017

Holy Crap! Thanks so much!!

Copy link

EwanMcP commented Mar 23, 2017

Respect, very handy. Thanks.

Copy link

shane-reaume commented Apr 24, 2017

Looks like this is old? getLocationAbsUrl() is returning as deprecated.

Copy link

arionalmond commented May 4, 2017

element('user_name').sendKeys("user1"); Needs to be changed to element('user_name')).sendKeys("user1"); Missed a parenthesis.

Copy link

daominhdam commented May 30, 2017

Thanks you so much!

Copy link

John-Okleberry commented Jul 17, 2017

This is great! I'm just starting out on Protractor but, if I come across something useful, I'll try to contribute.

Copy link

arepalli-praveenkumar commented Sep 11, 2017

Thank you

Copy link

daominhdam commented Sep 25, 2017

Thanks you

Copy link

masashiyokoi commented Dec 8, 2017

Thank you very match.

Copy link

husseinkorly commented Dec 15, 2017

Thank you

Copy link

maldzi commented Dec 30, 2017

It's so useful, thank.

Copy link

SiddharthDivakaran commented Apr 19, 2018

It's really useful thanks.

Copy link

chitranshamahor commented May 2, 2018

Great !!

Copy link

akshayraikar1 commented May 24, 2018

Thanks a lot, much appreciated.

Copy link

flashjpr commented Aug 7, 2018


Copy link

amandarfernandes commented Sep 15, 2018

Nice! Thank you

Copy link

vermin-scripts commented Nov 5, 2018

Thanks This helped a-lot

Copy link

Umesh2Patel commented Nov 6, 2018

Thank you. This is very helpful.

Copy link

nitin4tstin commented Nov 22, 2018

Excellent! time-saving... Thanks

Copy link

prajaktashah commented Jan 15, 2019

Awesome.....Time saving..Thanks a ton.

Copy link

manish-kumar0525 commented Jan 28, 2019

Great resource, concise and to the point.Thank you

Copy link

vmmartinezlona commented May 24, 2019


Copy link

shamir456 commented Aug 24, 2019

Very helpful

Copy link

Vicropht commented Sep 10, 2019


Copy link

HubertArciszewski95 commented Sep 24, 2019

Wow great, this is what I was looking for :)

Copy link

josejdlp commented Oct 1, 2019

Thanks +1

Copy link

sunilangadi2 commented Feb 13, 2020

Thanks a lot..!!!

Copy link

ramusarithak commented Mar 10, 2021

"" superrrrrr and very helpful ""

Copy link

nvn27 commented Mar 27, 2021

Thank you, much appreciated...!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment