Protractor: Scrolling a table and testing for infinite scroll

吃可爱长大的小学妹 提交于 2019-11-29 08:08:27
alecxe

The idea is to find the latest element in the table (tr tag) and scroll to it by setting the parent's scrollTop to the last element's offsetTop.

The Element.scrollTop property gets or sets the number of pixels that the content of an element is scrolled upward. An element's scrollTop is a measurement of the distance of an element's top to its topmost visible content.

The HTMLElement.offsetTop read-only property returns the distance of the current element relative to the top of the offsetParent node.

var div = element(by.css('div.table-scroll'));
var lastRow = element(by.css('table#myid tr:last-of-type'));

browser.executeScript("return arguments[0].offsetTop;", lastRow.getWebElement()).then(function (offset) {
    browser.executeScript('arguments[0].scrollTop = arguments[1];', div.getWebElement(), offset).then(function() {
        // assertions

    });
});

Also see (similar solution used):

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