如何单击在赛普拉斯中不可见的元素?

How to click an element that's not visible in Cypress?

我遇到了这个错误 运行 在 Cypress 中进行的测试:

Timed out retrying after 10050ms: cy.click() failed because this element is not visible:

我怎样才能点击它?它只是一个菜单项,我不需要它在我的测试中可见。

您必须添加 {force: true} 并且它应该使点击发生:

cy.get('locator').click({force: true})