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

Edg*_*nez 6 javascript angularjs-e2e protractor

我正在尝试确保在单击某个跨度时页面滚动到元素.所以我需要检查元素的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 
        });

    });

  });
Run Code Online (Sandbox Code Playgroud)

ale*_*cxe 6

你可以使用getLocation()功能:

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

  • 这得到了相对位置.你如何获得绝对位置? (4认同)