Dominik Skála
Dominik Skála

Reputation: 831

Cypress - Can't type in field

I have problem with typing in one of my fields in automated test. I can't get this field but I don't know why.

This is my code:

cy.get('#reasonRecommendationByAgent')
  .type('Zdůvodnění doporučení zprostředkovatele', {force: true})
  .should('have.value', 'Zdůvodnění doporučení zprostředkovatele')

And this is the error message:

enter image description here

Is there anyone who has the same problem?

Upvotes: 9

Views: 14025

Answers (3)

Optimworks
Optimworks

Reputation: 2547

Try adding a click() before you type:

cy.get('#reasonRecommendationByAgent')
  .click()
  .type('Zdůvodnění doporučení zprostředkovatele', {force: true})
  .should('have.value', 'Zdůvodnění doporučení zprostředkovatele')

Upvotes: 12

N..
N..

Reputation: 956

We had a similar problem and I was able to fix by adding click and focused. I think, HELP DOCS documents also recommending this.

cy.get('#reasonRecommendationByAgent').click().focused()
            .type('Zdůvodnění doporučení zprostředkovatele', {force: true})
            .should('have.value', 'Zdůvodnění doporučení zprostředkovatele')

Upvotes: 8

Zach Bloomquist
Zach Bloomquist

Reputation: 5871

According to the error message, it sounds like your code is removing/adding the #reasonRecommendationByAgent when it's typed into, which is causing Cypress to lose access to it.

Remove any code that might be causing this DOM element to change as it's being typed into and you shouldn't have a problem.

Upvotes: 0

Related Questions