I'm using Cypress 11.2.0 with Pragmatic DnD library - testing the drag and drop of elements.
In my Cypress test, when using getBoundingClientRect
it returns an empty object {}
. This should be returning data including the x
and y
co-ordinates of the element. Any idea how to get the co-ordinates of an element in Cypress?
cy.get('[data-test="drag-handle"]')
.first()
.then(($target) => {
let coordsDrop = $target[0].getBoundingClientRect();
cy.log('coordsDrop', coordsDrop);
})
There is no way an element returns an empty bounding client rect, you just need to look a bit harder.
For example.com:
cy.visit('https://example.com');
cy.get('h1')
.first()
.then(($target) => {
let coordsDrop = $target[0].getBoundingClientRect();
cy.log('coordsDrop', coordsDrop);
console.log('coordsDrop', coordsDrop);
})
The log:
Click the log entry:
or use consolg.log(coords)