automationautomated-testscypress

Is it possible to use two objects: Force and Multiple in Cypress Test?


I am using cypress test to check all the buttons in the page whether they can be clicked or not.

I have used this line of code:

cy.get('button').click({ force: true }).should('have.attr', 'href')

and gives error

CypressError: cy.click() can only be called on a single element. Your subject contained 5 elements. Pass { multiple: true } if you want to serially click each element.

After that changed code with:

cy.get('button').click({ multiple: true }).should('have.attr', 'href')

and got another error

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

...

This element '' is not visible because it has CSS property: 'display: none'

Fix this problem, or use {force: true} to disable error checking.

https://on.cypress.io/element-cannot-be-interacted-with

Is there any way to use both object to solve the problem?


Solution

  • This should work (I don't have a situation to test it when both needed, but it doesn't result in an error):

    cy.get('button')
      .click({ multiple: true, force: true })
      .should('have.attr', 'href')