无法记录表格中的列文本(量角器)

问题描述 投票:1回答:2

我有一个像这样的表xpath

enter image description here

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

我不知道我在这里错过了什么不行,因为我是量角器的新手,有人可以帮我解决我的功能有什么问题。

typescript xpath html-table protractor ui-automation
2个回答
2
投票

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

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

1
投票

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

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

column.getText().then(function(text) {
    console.log(text);
});
© www.soinside.com 2019 - 2024. All rights reserved.