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

133
Views
Cypress unable to find selector - React/CSS Modules/Cypress

I am writing e-2-e tests for our frontend using Cypress.

When I try to target an element, I am using .button-module_btnLabel__30kQb, but as I understand this makes my test brittle as the classname hash may change.

However, when I try to add a selector, Cypress can't find it. An example below:

import { Button } from '...ui'
      <Button.Primary
        data-cy="submit"
        onClick={startLogin}
      >
        Log In
      </Button.Primary>
      cy.get('data-cy="submit"')
      .should('be.visible')
      .should('contain.text','Log In')
      .click()
     AssertionError: Timed out retrying after 4000ms: Expected to find element: `[data-cy=submit]`, but never found it.
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you are selecting on an attribute, you need enclosing square brackets.

cy.get('[data-cy="submit"]')

Note React does not pass on all attributes, but data prefix should be ok.

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!