目标:我想使用Cypress中的无障碍选择器点击页面上特定的元素。
代码:
cy.findAllByRole('rowheader').eq(2).click();
错误
Timed out retrying: cy.click() failed because this element is detached from the DOM.
<th scope="row" data-automation-id="taskItem" aria-invalid="false" tabindex="-1" class="css-5xw9jq">...</th>
Cypress requires elements be attached in the DOM to interact with them.
The previous command that ran was:
> cy.eq()
This DOM element likely became detached somewhere between the previous and current command.
问题: 从DOM中我可以看到这个元素还在 - 没有逻辑将此元素从DOM中分离, 而eq方法肯定不会这么做。此外,findAllByRow方法显然正在工作,因为它找到了我想要点击的正确th元素。为什么它说元素被分离了?有没有解决这种情况的方法?
findAllByRole()
和.eq(2)
之间不可能出现元素分离的情况,因此问题必定出现在这之前的某个命令上。你能展示完整的测试吗? - user12697177