0
votes

I am automating a test on a page and I need to click the "Add images" button. But it's not reacting

<button class="btn btn-default awe-hidden" id="html5button" onclick="$('#html5files').click();return false;">Add images</button>

I have tried

  1. cy.get('button').contains('Add images').click()
  2. cy.get('button').contains('Add images').invoke('show').click()
  3. cy.get('button').contains('Add images').invoke('show').click({force: true})
  4. cy.get('button').contains('Add images').trigger('mouseover').dblclick()
  5. Also tried trigger 'mousedown', short wait then 'mouseup'
  6. Also tried cy.contains('Add images').click()

Any ideas?

1
can you please provide the error message/stacktrace of your failing test?DieGraueEminenz
It may be because the onclick contains jquery code. Try using cypress-real-events cy.get('button').realClick()user9622173
Thanks @DieGraueEminenz but there is no error message displayed.Lasse
@Sarah thank you that solves it :) If you post it as the answer I will mark it.Lasse

1 Answers

1
votes

The onclick() event handler contains a jQuery expression, but I suspect Cypress doesn't handle it properly.

You can use cypress-real-events instead

cy.get('button').realClick()