我正在使用以下代码从 < 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 });
})
您可以使用 aliases 为此。
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
})