admin管理员组文章数量:1357724
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?
1 Answer
Reset to default 9You 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);
});
本文标签: javascriptGetting the button text in ProtractorStack Overflow
版权声明:本文标题:javascript - Getting the button text in Protractor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744080924a2587622.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论