最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting the button text in Protractor - Stack Overflow

programmeradmin5浏览0评论

I have created a custom locator to find an element with the ng-click method used. I have used it to get a reference to a button in my DOM.

this.button = element(by.ngClick('login()'));

i want to get the text that is on the button from the reference. For example if the button has "Click to Login" as the text, how can i extract that from the button reference?

I have created a custom locator to find an element with the ng-click method used. I have used it to get a reference to a button in my DOM.

this.button = element(by.ngClick('login()'));

i want to get the text that is on the button from the reference. For example if the button has "Click to Login" as the text, how can i extract that from the button reference?

Share Improve this question asked Jun 8, 2015 at 5:57 Kasun KodagodaKasun Kodagoda 4,0245 gold badges33 silver badges54 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

You can call getText() on the element selector, but keep in mind it returns a promise. The promise could be fed to expect though, it would resolve it and perform the parision:

expect(this.button.getText()).toBe('Click to Login');

If you need to use the text for anything else in your code you'll have to resolve the promise yourself:

this.button.getText().then(function (text) {
    console.log(text);
});
发布评论

评论列表(0)

  1. 暂无评论