[英]Unable to log columns text in a table (Protractor)
我有一个像这样的表xpath
element(by.xpath('(//div[@class='sprk-b-TableContainer'])[3]//tbody'));
我写了一个函数,它接受webelement并记录列文本
public logTableData(table: ElementFinder) {
table.$$('tr').filter(function (row): any {
row.$$('td').filter(function (column): any {
console.log(column.getText());
});
});
}
我不知道我在这里错过了什么不行,因为我是量角器的新手,有人可以帮我解决我的功能有什么问题。
我尝试过如下,它解决了我的问题
public logTableData(table: ElementFinder) {
const rows = table.$$('tr');
rows.each((row) => {
const cells = row.$$('td');
cells.each((cell) => {
cell.getText().then((cellText) => {
console.log('Failure Reason :: ' + cellText);
});
});
});
}
getText()
是异步的,但实际上并没有等待返回结果。
更改它以便您在记录之前等待文本:
column.getText().then(function(text) {
console.log(text);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.