Get element's offset position with protractor
Asked Answered
D

1

6

I am trying to make sure the page scrolls to an element when a certain span is clicked. So I need to check the element's y position. Can someone explain how I can get an element's position?

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 
        });

    });

  });
Duce answered 6/3, 2015 at 0:21 Comment(0)
D
8

You can use getLocation() function:

element(by.id('section-executive-summary-anchor')).getLocation().then(function (location) {
    expect(location.y).toEqual(100);
});
Diastema answered 6/3, 2015 at 0:24 Comment(1)
This gets the relative location. How do you get the absolute location?Cheiro

© 2022 - 2024 — McMap. All rights reserved.