问题
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.
回答1:
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);");
回答2:
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.
来源:https://stackoverflow.com/questions/27110267/protractor-send-a-scroll-command-to-an-element-div-etc