根据文本循环遍历柏树元素

时间:2020-10-16 18:23:17

标签: typescript testing cypress

我要测试的页面上有多个带有文本Order的按钮。我正在尝试获取所有这些按钮并遍历它们。

我不能使用cy.get('button).contains('Order'),因为它只会返回第一个按钮。有办法吗?

我什至试图循环所有按钮

cy.get('button').each(($button, index) => {
    if ($button.text() == 'Order') {
        cy.wrap($button).click();
    }
});

但这会在第二个按钮上引发错误

cy.click() failed because this element is detached from the DOM.

任何帮助表示赞赏。

0 个答案:

没有答案