Protractor Testing (Using Selenium and Chrome on angular site) gives wrong x and y point
In the actual test a simple button.click() is called and that is what is missing the button by about 50px
In this case, move to the element first and then perform a click:
browser.actions().mouseMove(button).click().perform();
Or, scroll into view of the element:
browser.executeScript("arguments[0].scrollIntoView();", button.getWebElement());button.click();
Note that getLocation()
itself depends on the visible area - the viewport that a browser determines. It may be different in different browsers and different operating systems. See also:
And, you can actually get the viewport
size and compare it on the browsers and systems you execute your tests on - I'm pretty sure you'll get different values, see:
You may also look into what getBoundingClientRect()
returns in your case:
The
Element.getBoundingClientRect()
method returns the size of an element and its position relative to the viewport.
browser.executeScript("return arguments[0].getBoundingClientRect();", button.getWebElement()).then(function (rect) { console.log(rect.left); console.log(rect.top);});