Protractor send a scroll command to an element (div etc)

倖福魔咒の 提交于 2019-12-23 23:01:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!