获取元素's用量角器偏移的位置

Get element's offset position with protractor

本文关键字:量角器 位置 元素 获取      更新时间:2023-09-26

我正在努力确保在单击某个跨度时页面滚动到某个元素。所以我需要检查元素的y位置。有人能解释一下我如何获得元素的位置吗?

element.all(by.css('[scroll-to="section-executive-summary-anchor"]'))
  .then(function (elem) {
    elem[0].click().then(function () {
      element(by.id('section-executive-summary-anchor'))
        .then(function (el) {
          // I need "el.position" or something along those lines 
        });
    });
  });

您可以使用getLocation()函数:

element(by.id('section-executive-summary-anchor')).getLocation().then(function (location) {
    expect(location.y).toEqual(100);
});