Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!