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

413
Vistas
How to test relative positioning of elements in cypress?

I am currently new to cypress and wants to test that Forgot Password should be below Login button in Facebook page? Is there a way to do that? Facebook page

Is there a way to test relative positioning of elements in cypress?

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

0

I think you can use jQuery .position()

cy.get('#element1')
  .then($el => $el.position().top)  // get 1st top value
  .then(top1 => {
    cy.get('#element2')
      .then($el => $el.position().top)  // get 2nd top value
      .then(top2 => {
        expect(top1).to.be.gt(top2)
      })
  })

Notes

Cypress use jQuery to find elements. Chaining .then($el => ... exposes the jQuery object containing the element, so now you can apply other jQuery functions that are not part of the Cypress commands.

In fact, any other Javascript functions you want.

You can also make reusable functions

const getTop = ($el) = $el.position().top;

cy.get('#element1').then(getTop)  
  .then(top1 => {
    cy.get('#element2').then(getTop)
      .then(top2 => {
        expect(top1).to.be.gt(top2)
      })
  })
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use the cypress method next() to determine the element next to Log in button like this. next() gets the immediately following sibling of each DOM element within a set of DOM elements.

cy.get('div[type="submit"]').next().should('have.text', 'Forgot password?')
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