I was using following code
element(by.xpath("//tf-navpane-item[contains(@class,'tf-state-selected')]//tf-navpane-item-text//*[contains(@class,'ng-binding')]")).then(function(ele){
ele.getText().then(function(txt){
console.log("txt: "+txt);
});
});
This code used to work fine when I was using Protractor 1.0. After upgrading Protractor to 3.2.1 ,I started to get following error.
TypeError: element(...).then is not a function
I maybe missing something but not sure what.
Yeah, this is something you should expect since the element()
cannot be directly resolved with then()
anymore (breaking change in Protractor 2.0). Instead, do:
var elm = element(by.xpath("//tf-navpane-item[contains(@class,'tf-state-selected')]//tf-navpane-item-text//*[contains(@class,'ng-binding')]"));
elm.getText().then(function(txt) {
console.log("txt: " + txt);
});
Note that, if you would need to assert the text, you can pass the getText()
into expect()
- it understands what a promise is and would resolve it before making an expectation:
expect(elm.getText()).toEqual("Expected text");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With