Protractor: element.getText() returns an object and not String(量角器:element.getText() 返回一个对象而不是字符串)
问题描述
我有一个元素定义为
this.clientRowName = element(by.id('CLIENT_NAME')); //page object file
我想阅读这个元素中的文本,它是ABC",但是这样做:var client = page.clientRowName.getText();
I want to read the text in this element which is "ABC" but doing: var client = page.clientRowName.getText();
返回一个对象而不是一个字符串.有没有其他方法可以获取元素的文本
returns an object instead of a string. Is there any other way that I can get the text for the element
推荐答案
getText()
返回一个promise,你需要解决它:
page.clientRowName.getText().then(function (text) {
console.log(text);
});
或者,如果你只想断言文本,让 expect()
为你解析承诺:
Or, if you just want to assert the text, let expect()
resolve the promise for you:
expect(page.clientRowName.getText()).toEqual("ABC");
承诺和控制流 文档页面应该可以解决问题.
Promises and the Control Flow documentation page should clear things up.
这篇关于量角器:element.getText() 返回一个对象而不是字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:量角器:element.getText() 返回一个对象而不是字符串


基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01