0

我正在使用以下代码从 < td > 获取文本值:

 let serviceName;
    cy.get('tr').eq(1).then(row => {
        cy.wrap(row).find('td').eq(1).invoke('prop', 'innerText').then(val => { serviceName = val });
    })

它在某些页面上工作正常,而不是在其他具有相同表类型/类/等的页面上工作正常。前端是用 Angular 构建的

使用这样的相同代码也会失败:

let serviceName;
    cy.get('tr').eq(1).find('td').eq(1).invoke('prop', 'innerText').then(val => { serviceName = val });
    })
4

1 回答 1

0

您可以为此使用别名。

cy.get('tr')
  .eq(1)
  .find('td', {timeout: 5000})
  .eq(1)
  .should('be.visible')
  .invoke('prop', 'innerText')
  .as('text')

cy.get('@text').then((text) => {
  //access text here
})
于 2022-02-08T11:41:12.800 回答