Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

269
Vistas
Cypress How do tick check boxes with no unique selectors

I am trying to select/tick checkboxes with no obvious selectors but a class name which is shared by all the checkboxes on the page.

Can someone please share how I can test these elements with no selectors.

I am testing a search engine.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Then You can directly use the text to find the locator and click it, something like:

cy.contains('Tool').click()

For the search button, you have the aria-label tag, you can use that directly:

cy.get('input[aria-label*="main-search-box"]').type('text')
about 4 years ago · Juan Pablo Isaza Denunciar

0

I believe it goes against cypress' best practices to try and select any element other than using data-cy="add-unique-id-here" selector. The docs suggest that using CSS-style selectors is brittle, and may cause tests to fail in the future when you update your code. By using data-* selectors, you can gaurantee you're always selecting what you need.

Here's the link for the cypress docs: https://docs.cypress.io/guides/references/best-practices#Selecting-Elements

Example code from cypress docs

In your case, adding <span class="ui-lib-checkbox__box" data-cy="descriptive-checkbox-name"> <svg>...</svg> </span> to your html

and cy.get('[data-cy=descriptive-checkbox-name]') to your cypress testing file, should do the trick.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Given the text for the checkboxes are unique, you can use cy.contains()

// 'Under 6 min' checkbox
cy.contains('span', 'Under 6 min')

// 'Tool' checkbox
cy.contains('span', 'Tool')

As for the search box, it will get a bit trickier. If it is the only search box that is visible on the page you can do the following.

cy.get('input[type=text][placeholder]')
  .filter(':visible')
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda