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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.