I have the following checkbox element
<ion-checkbox _ngcontent-dul-c225="" data-cy="terms-of-sale-checkbox"
formcontrolname="acceptTermsOfSale" data-name="cta_confirmtermsofsale" aria-checked="false" role="checkbox">
<input type="hidden"
name="ion-cb-0" value="">
</ion-checkbox>
I have tried to click the check box using
cy.get('[data-cy="terms-of-sale-checkbox"]:last input').should('exist').click({force: true, multiple: true});
cy.get('[data-cy="terms-of-sale-checkbox"] input').should('exist').click({force: true, multiple: true});
cy.get('[data-cy="terms-of-sale-checkbox"]').check()
neither one has worked , the element does not get clicked, the value dose not change
I am using cypess 7 with macos. the browser is chrome.
EDIT: On the page I have a single checkbox "Terms of sale" which needs to be clicked
CodePudding user response:
You can use contains with the combination of text and selector.
cy.contains('[data-name="cta_confirmtermsofsale"]', 'Terms of sale')
.should('exist')
.click()
or with {force: true}
cy.contains('[data-name="cta_confirmtermsofsale"]', 'Terms of sale')
.should('exist')
.click({force: true})
CodePudding user response:
Try this :
cy.get('[data-cy="terms-of-sale-checkbox"] input').should('include.text', 'Terms of sale')
or
cy.get('[data-cy="terms-of-sale-checkbox"] input').invoke('text').then(text) => {
expect(text).contains('Terms of sale')
}
it mite help you.
