Calling an element (locator) .sendKeys returns a promise that is either allowed or rejected. The promise is part of the control flow.
Calling an element (locator) by itself does not cause an error, it is a promise that is rejected. If you were unable to find the item, in fact you want your entire test to fail, since scneario cannot be completed.
To get the error message, you can use callbacks as shown below.
Important Note : If you handle the failure of promises yourself, your test will not fail, so you better rebuild it.
try { element(by.id('usernameas')).sendKeys(data).then(function() { console.log('keys sent successfully'); }, function(err) { console.error('error sending keys ' + err); throw err; }); } catch(err) { console.log('error occured'); }
Console exit (cut off):
error sending keys NoSuchElementError: no such element (Session info: chrome=31.0.1650.63) (Driver info: chromedriver=2.8.241075,platform=Windows NT 6.1 S .....
source share