量角器 - 如何使用多滤波器查找目标行



我想滤除包含单元单元中特定文本的目标行属于此行。

这是我的代码:

 private selectTargetLicense(licenseName: string) {
    return new Promise((resolve => {
      element.all(by.tagName('clr-dg-table-wrapper')).first().all(by.tagName('clr-dg-row')).filter(function (row_element) {
        return row_element.all(by.tagName('clr-dg-cell')).filter(function (cell) {
          return cell.getWebElement().getText().then(function (text) {
            return text.trim() === licenseName;
          })
        })
      }).first().getWebElement().click().then(() => {
        resolve();
      })
    }))
  }

它不起作用,因为我认为未能从表中的行获得目标行。

那么我应该如何正确使用多滤波器?

谢谢。

在没有HTML代码的情况下,很难研究您的代码。你能告诉我们吗?

您要单击带有给定文本或整个行的单元格吗?

单击单元格的代码:

private selectTargetLicense(licenseName: string) {
const rows = element.all(by.css('clr-dg-table-wrapper:nth-of-type(1) clr-dg-row clr-dg-cell'));
return rows.filter((row_element) => {
    return row_element.getText().then((text) => {
        return text.trim() === licenseName;
    });
}).first().click();

}

无需使用嵌套的filter,行上的过滤器就足够了。

private selectTargetLicense(licenseName: string) {
    const rows = element(by.css('clr-dg-table-wrapper')).all(by.css('clr-dg-row'));
    rows.filter((row) => {
        // read text of all cells of one row into array: txts
        return row.all(by.css('clr-dg-cell')).getText().then((txts) => {
            return txts.map((it)=>{
                        // trim each text
                        return it.trim();
                   })
                   // use array.includes() to detect row contains specified licenseName
                   .includes(licenseName);
        });
    })
    .first()
    .click();
}

最新更新