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

189
Visualizações
Unable to find element after adding className in html file

If I am manually adding id , test-id or classname in html file . Here I have added 'Classname' just as an example to show you.

enter image description here Cypress is not able to find the elemententer image description here

using cy.get(".todo-list") to locate the button as I have mentioned classname (shown in screenshot). enter image description here

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

0

Try using the class instead of className attribute on the button. For example, class="todo-list".

Some things like JSX in React use className due to the fact that class is a reserved keyword in JavaScript, but since this is vanilla HTML it isn't necessary. Also, for the future, could you paste the code snippets instead of just screenshots?

about 4 years ago · Juan Pablo Isaza Relatório

0

@Bryce is correct (assuming it's not a React app), but in general any attribute can be queried using an extended syntax

cy.get('[className="todo-list"]')

Looking at the UIKit docs,

By default, all classes and attributes in UIkit start with the uk- prefix. This avoids name collisions when introducing UIkit to existing projects or when combining it with other frameworks.

so maybe add the class prefix uk- (although this may just be to avoid conflict in the style sheets and have no bearing on the test).

<button class="uk-todo-list" >
cy.get('.todo-list')

Generally speaking, using a class is less solid than using a data-cy attribute, since classes also control styling and may be changed in the future.

Cypress recommends this

<button data-cy="todo-list" >
cy.get('[data-cy="todo-list"]')
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