本文介紹了量角器: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() 返回一個對象而不是字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!