Cypress 结果为“指针事件:无”使用条件时出错,怎么办?
我想单击“下一步”按钮来测试分页,直到其类被“禁用”。 我使用了下面的代码。但即使“下一步”按钮具有“禁用”类别,它仍会继续单击。赛普拉斯在附件中抛出错误。
static pagination(){
var index = 0
cy.get('li [data-test="page-link"]:not(.active):not([aria-label="Next"]) :not([aria-label="Previous"]').as("pages")
cy.get('@pages').its('length').then( len =>{
if(index <= len){
cy.get('[data-test="page-link"][aria-label="Next"]').then( next=>{
cy.wrap(next).invoke('hasClass', 'disabled').then( classDisable =>{
if(classDisable==false){
cy.wait(500)
cy.wrap(next).should('not.have.class', 'disabled')
cy.wrap(next).click()
}
this.pagination()
index++
})
})
}
})
}
I want to click on Next button to test pagination, until its class is "disabled".
I used the code below. But it continues to click even "Next" button has "disabled" class. And Cypress throws the error at the attachment.
static pagination(){
var index = 0
cy.get('li [data-test="page-link"]:not(.active):not([aria-label="Next"]) :not([aria-label="Previous"]').as("pages")
cy.get('@pages').its('length').then( len =>{
if(index <= len){
cy.get('[data-test="page-link"][aria-label="Next"]').then( next=>{
cy.wrap(next).invoke('hasClass', 'disabled').then( classDisable =>{
if(classDisable==false){
cy.wait(500)
cy.wrap(next).should('not.have.class', 'disabled')
cy.wrap(next).click()
}
this.pagination()
index++
})
})
}
})
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有可能完全避免条件检查。
如果您可以获取“Next”左侧框中的数字 - 我猜测
.prev()
会获取它,但您可能需要调整该步骤。然后你可以点击() pageCount-1 次。
It may be possible to avoid the conditional check altogether.
If you can get the number in the box to the left of "Next" - I'm taking a guess that
.prev()
will get it, but you may have to adjust that step.Then you can click() pageCount-1 times.
这可能是您想要的
如果从一开始就禁用“下一步”按钮,它也应该起作用。
This could be what you want
It should also work if Next button is disabled from the start.
如果你想点击禁用的按钮,你必须使用
{force: true}
并且,如果你想先检查按钮是否启用,然后执行点击,你可以这样做:
If you want to click on the disabled button you have to use
{force: true}
And, if you want to first check whether the button is enabled or not and then perform click, you can do something like:
尝试在下次单击时将强制选项设置为 true。
Try setting the force option to true on the next click.