我编写了以下代码以从表中返回文本。
现在,我想要的是:dnassgn
是页面名称,但调用该函数后,返回值为空白。请告诉我哪里错了。
fetch_text_from_cell_in_table: function(col_val){
var name_var="";
var km = 0;
var dm = 0;
pointer1 = element.all(by.repeater('row in renderedRows')).then(function(posts) {
for (ni = 0; ni < posts.length; ni++)
name_var= posts[ni].element(by.className(col_val)).getText().then(function(name){
//console.log(valdation_value);
console.log(col_val);
console.log(name);
var name_var = name.trim();
return name;
});
});
return name_var;
},
var dn_num=dnassgn.fetch_text_from_cell_in_table('colt0');
expect(dn_num).toBe('Not Found');
最佳答案
首先,您没有从您的函数返回任何内容。
此外,据我了解,您需要过滤表格并获取特定列中单元格的文本值(具有特定类名的单元格,例如 colt0
)。使用 map()
:
function fetch_text_from_cell_in_table (col_val) {
return element.all(by.repeater('row in renderedRows')).map(function(post) {
return post.element(by.className(col_val)).getText();
});
});
用法:
var dn_num = dnassgn.fetch_text_from_cell_in_table('colt0');
expect(dn_num).toBe(['Not Found']);
关于javascript - 如何从 Protractor 返回对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30757107/