Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

247
Visualizações
How to hold shift and use arrow keys in Cypress

I have an issue when using the Cypress type() command in the way I want.

My objective

I want to be able to select and delete text in a textfield. I want this done via holding the shift key, pressing the right arrow key multiple times and then pressing the delete key.

My attempt

//hold shift and use right arrow
cy.type('{shift}{rightarrow}'.repeat(10));
//press delete
cy.type('{del}');

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

As per the available information instead of repeat, you can use the Cypress._.times loadash method. This will run the entire type command 10 times.

Cypress._.times(10, () => {
  cy.type('{shift}{rightarrow}')
})
about 4 years ago · Juan Pablo Isaza Relatório

0

The element needs focus before applying arrow keys,

cy.get('#myinput')
  .focus()
  .type(Cypress._.repeat('{shift}{rightarrow}', 5))
  .type('{del}')

This gets the cursor moving within the the element's text, but unfortunately does not extend the selection, so {del} only removes one element.

You can use an internal input method instead of {shift}{rightarrow}, if this suits your test

cy.get('#myinput')
  .focus()
  .then($el => $el[0].setSelectionRange(0, 5))
  .type('{del}')

To clear completely,

cy.get('#myinput')
  .clear()          // types {selectall}{del}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda