我希望能够单击复选框,并测试元素不再在Cypress的DOM中。有人能建议你怎么做吗?

// This is the Test when the checkbox is clicked and the element is there

cy.get('[type="checkbox"]').click();
cy.get('.check-box-sub-text').contains('Some text in this div.')

我想做与上面的测试相反的事情。

所以当我再次点击它的div类复选框子文本不应该在DOM。


当前回答

您也可以使用下面的代码

expect(opportunitynametext.include("Addon")).to.be.false

or

should('be.not.be.visible')

or

should('have.attr','minlength','2')

其他回答

您还可以同时使用get和contains来区分HTML元素。

<button type='button'>Text 1</button>
<button type='button'>Text 2</button>

假设你有两个不同文本的按钮,你想检查第一个按钮是否不存在,然后你可以使用;

cy.get('button').contains('Text 1').should('not.exist')

您也可以使用下面的代码

expect(opportunitynametext.include("Addon")).to.be.false

or

should('be.not.be.visible')

or

should('have.attr','minlength','2')

柏树中没有试接流

在java-selenium中,我们通常添加NoSuchElementException并执行case。如果UI没有显示某些基于角色的访问情况下的元素。

我会用:

cy.get (.check-box-sub-text)登陆(“not.be.visible”);

这比

cy.get (.check-box-sub-text)登陆(“not.exist”);

(元素可以出现在DOM中,但不可见display: none或不透明度:0)

如果没有元素,我们可以使用简单的行:

cy。get (' [type = "复选框“]”)。should(“not exist。”)