Tools.js 460 B

123456789101112131415161718192021
  1. const { I } = inject();
  2. module.exports = {
  3. async getElementPosition(elementSelector) {
  4. const pos = await I.executeScript((selector) => {
  5. const elem = document.querySelector(selector);
  6. const pos = elem?.getBoundingClientRect();
  7. return pos
  8. ? {
  9. x: pos.x,
  10. y: pos.y,
  11. width: pos.width,
  12. height: pos.height,
  13. }
  14. : null;
  15. }, elementSelector);
  16. return pos;
  17. },
  18. };