小编Gwy*_*ynn的帖子

为什么 Cypress 在运行 get 命令后说我的元素已分离?

目标: 我想使用 cypress 的辅助功能选择器单击页面上的特定元素

代码

cy.findAllByRole('rowheader').eq(2).click();
Run Code Online (Sandbox Code Playgroud)

错误

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.
Run Code Online (Sandbox Code Playgroud)

问题: 我可以在 DOM 中看到该元素仍然存在 - 没有逻辑将该元素与 DOM 分离,并且 eq 方法当然不会这样做。此外,findAllByRow 方法显然正在工作,因为它找到了我想要单击的正确元素。怎么会说五行分离呢?对于这种情况有解决方法吗?

javascript automation browser-automation cypress

54
推荐指数
6
解决办法
6万
查看次数