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

126
Vistas
Cypress.$('abc').text() returns undefined

I am trying to find a text of element using Cypress.$ All is working well with cy object but the Cypress.$ yields undefined

//This works

cy.get('abc').eq(0).find('xyz').then(($elm)=>{
                cy.log("$elm="+$elm.text())
            })

//This yields "undefined"

var elmText = Cypress.$('abc').eq(0).find('xyz').text()
cy.log(elmText)

Can some one help why Cypress.$ does not works here ??

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

0

I can only guess that you have some cypress commands that must be completed before querying the selector. As cypress commands are asynchronous, your UI state is not ready when jquery is executed. Thus, you can make it executed synchronously with cypress commands as follows:

cy.then(() => {
   var elmText = Cypress.$('abc').eq(0).find('xyz').text()
   cy.log(elmText)
})
about 4 years ago · Juan Pablo Isaza Denunciar

0

@MikhailBolotov is correct, synchronous code like Cypress.$ in the same block as commands runs first.

Try out out this simple visit and heading check.

it('asynchronous commands', () => {
  cy.visit('http://example.com')
    .then(() => console.log('After visit'))

  var elmText = Cypress.$('h1').text()
  cy.log(elmText)
  console.log('At end of test')
})

The order of console.logs is

  1. At end of test
  2. After visit

As well as @MikhailBolotov'a suggestion, you can use hooks like beforeEach to break up the block and achieve what you want.

beforeEach(() => {
  cy.visit('http://example.com')
    .then(() => console.log('After visit'))
})

it('asynchronous commands', () => {
  var elmText = Cypress.$('h1').text()
  cy.log(elmText)
  console.log('At end of test')
})

The order of console.logs is now correct

  1. After visit
  2. At end of test
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