量角器:element.getText() 返回一个对象而不是 String [英] Protractor: element.getText() returns an object and not String

查看:25
本文介绍了量角器:element.getText() 返回一个对象而不是 String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个元素定义为

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 和控制流 文档页面应该清除一切.

Promises and the Control Flow documentation page should clear things up.

这篇关于量角器:element.getText() 返回一个对象而不是 String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆