无法在 table(量角器)中记录列文本

Unable to log columns text in a table (Protractor)

我有一个 table 这样的 xpath

 element(by.xpath('(//div[@class='sprk-b-TableContainer'])[3]//tbody'));

我写了一个函数,它接受网络元素并记录列文本

public logTableData(table: ElementFinder) {

        table.$$('tr').filter(function (row): any {
            row.$$('td').filter(function (column): any {
                console.log(column.getText());
            });
        });
    }

我不知道我在这里错过了什么它不起作用,因为我是量角器的新手,有人能帮我看看我的功能有什么问题吗。

getText() 是异步的,但您实际上并不是在等待返回结果。

更改它以便您在记录之前等待文本:

column.getText().then(function(text) {
    console.log(text);
});

我试过如下,它解决了我的问题

 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);
                });
            });
        });
    }