A J
A J

Reputation: 1545

Initial letters missing while using type() in Cypress

Scenario:

<tr>
  <td id="type1">
    <div><span></span></div>
  </td>
  <td id="type2">
    <div><span></span></div>
  </td>
</tr>
cy.get('#type1').type('Abcd') // skips the initial letters ie,   
                              // it actually types 'bcd' or 'cd'

There's an issue here Missing letters when using type #3817. I can see this issue is resolved, but I'm still facing this issue. Any workarounds?

Upvotes: 6

Views: 3262

Answers (1)

SSpall
SSpall

Reputation: 136

This question leaves out some vital bits that I would like to clear up.

If you try out the click-trick on that HTML snippet, you will come a cropper.

This is the error

cy.type() failed because it requires a valid typeable element.

A typeable element matches one of the following selectors:

a[href]  
area[href]  
input  
select  
textarea  
button  
iframe  
[tabindex]  
[contenteditable]  

The last two are the only options for this particular HMTL, so you could make it work like this:

cy.get('#type1')
  .invoke('attr', 'contenteditable')   // make it editable
  .type('Abcd')

  .should('contain', 'Abcd')           // confirm it has the text

  .invoke('removeAttr', 'contenteditable')     // optionally remove the attribute
  .should('not.have.attr', 'contenteditable')

Upvotes: 6

Related Questions