我有一个像这样的表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);
});