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

127
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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