Reputation: 1852
In protractor end to end test, how can one set the scroll value of an element (e.g. div), not entire page.
Something which by jQuery, one would simply call for example $('.myElement').scrollTop(100);
. This is because in my end to end test, I want to test that when one particular <div>
has scrolled, I want to assert that another <div>
must have be scrolled to keep in sync.
Upvotes: 2
Views: 5605
Reputation: 528
I needed the same mechanism and I created below util method and it works fine for me. ;)
element.getLocation().then(function (location) {
return browser.executeScript('window.scrollTo(' + location.x + ' , ' + location.y + ')');
});
In Btw, the below also works:
browser.actions().mouseMove(element).perform();
Choose your fav. ;)
I preferred the first one since the second one also triggers mouseOver style events.
Upvotes: 4
Reputation: 3172
selenium doesn't provide way to scroll at an element level.
if the jquery code does the scrolling, then run that code inside the browser like this
driver.executeScript("$('.myElement').scrollTop(100);");
Upvotes: 1