Reputation: 995
I'm trying to resolve one problem referred to protractor getText(). I have a code which finds successfully an element:
var $editTrigger = $('[ui-view="hcp"] .m-pane__control__trigger');
then execute a line that works too:
expect($editTrigger.getText()).toBe('BEARBEITEN');
but if I execute this
console.log('---> $expectTrigger' + $editTrigger.getText());
what I get it's: [object Object].
Why? Why don't I get 'BEARBEITEN'? This has happened to me several times and I don't know what do I do wrongly.
If you need more information to evaluated this case please feel free to ask for it. Thanks you
Upvotes: 2
Views: 890
Reputation: 751
getText() is an promise. the console.log will be executed long before the value from getText is returned. If you write it like a promise it works.
$editTrigger.getText().then(function(text){
console.log(text);
});
The expects work because they now they are working with a promise and wait for it to complete.
Upvotes: 3