Getting button text in Protractor
I created a custom locator to find the element with the method being used ng-click
. I used it to get a link to a button in my DOM.
this.button = element(by.ngClick('login()'));
I want to get the text that is on a button from a link. For example, if the text is a "Click to Login" button, how can I retrieve it from the help button
?
source to share
You can call getText()
on an element selector, but keep in mind that it returns a promise. A promise could have been posted to expect
, though it would resolve it and do the comparison:
expect(this.button.getText()).toBe('Click to Login');
If you need to use text for anything else in your code, you'll have to resolve the promise yourself:
this.button.getText().then(function (text) {
console.log(text);
});
source to share