Cypress Click using Position

Profile picture for user arilio666

In cypress, we can click with position, and it is super easy to do it.

Syntax:

cy.get('#id').click('topRight')
  • Now, these are the available positions that can be used in cypress.
  • topLeft, top, topRight, left, center, right, bottomLeft, bottom, and bottomRight.

Example:

  it('Visit Page',() => {
       cy.visit("https://www.programsbuzz.com/user/login")
       
cy.xpath("(//div[@class='row'])[2]").click('center')
   })
  • We can see the click position in the center where the username field is present.

Conclusion:

This is how we can click using position according to our needs.