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

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

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 Report

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