Subtubes
Subtubes

Reputation: 16873

Get element's offset position with protractor

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

    });

  });

Upvotes: 6

Views: 8909

Answers (1)

alecxe
alecxe

Reputation: 473853

You can use getLocation() function:

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

Upvotes: 8

Related Questions