Cy.get().type() does not seem to be registering as a keyboard event

Viewed 310

I'm new to cypress. I'm using cy.get('xpath to selector').type('something') to fill in a field that works fine. The issue I'm having is filling the field should enable a continue button but it's not. It enables if I manually type in the field. Any suggestions would be helpful.

2 Answers

You can first click() and then type.

cy.get('xpath to selector').click().type('something')

Or, you can use {force: true}, it forces the action and disables waiting for actionability.

cy.get('xpath to selector').type('something', {force: true}).type(‘{enter}’)

Probably just need to trigger the change event, since there is a side-effect happening (enabling the button).

Perhaps one of these

cy.get('selector').type('something').trigger('change')
cy.get('selector').type('something').trigger('input')     // or this event

less likely, you would notice if needed

cy.get('selector').type('something{enter}')
cy.get('selector').type('something').blur()    // aka tab off

Also possible validation slows down button enable, so next step in the test executes too fast.

cy.get('selector').type('something').trigger('change')
cy.get('button').should('be.enabled')    // wait explicitly for enabled 

One more guess

cy.get('form').submit()   // try the form submit
Related