Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is protractor.findElement() meant to scroll to that element?

My current unit test (protractor + angularJS project) is failing with the error UnknownError: unknown error: Element is not clickable at point (525, 1103). I used debugger to stop it just before failure, and the only reason I can think that it would fail is because the button is not in the view port (you would have to scroll down).

The failing lines are

homeLink = ptor.findElement(protractor.By.linkText('Home'));
homeLink.click();
expect(ptor.getCurrentUrl()).toBe(homeUrl);

From https://github.com/angular/protractor/issues/319, he says '...when i use findElement() it will scroll them to the "top" of the page'. And the comments agree.

In my test homeLink = ptor.findElement(protractor.By.linkText('Home')); is not causing the the page to scroll.

Am I wrong in thinking it should?

What should I be doing?

like image 496
Lango Avatar asked Feb 24 '14 10:02

Lango


1 Answers

You need to scroll down (or maximize browser if this allows you to see the button you would like to click on) first so that the button is visible on the page:

var scrollIntoView = function () {
    arguments[0].scrollIntoView();
}
browser.executeScript(scrollIntoView, yourwebelement);
like image 172
Ziwdigforbugs Avatar answered Nov 15 '22 10:11

Ziwdigforbugs