首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >量角器:滚动表格并测试无限大卷轴

量角器:滚动表格并测试无限大卷轴
EN

Stack Overflow用户
提问于 2015-01-06 07:53:51
回答 1查看 6.9K关注 0票数 3

我怎样才能让量角器在桌子上向下滚动?我的表进行无限滚动-它加载20个记录,当显示第二行到最后一行时,它将获取接下来的20个记录。并不是view...some中的所有记录都在下面有待滚动,而当用户滚动过它时,有些记录就在上面。我在想考试是

代码语言:javascript
运行
复制
it('should fetch next set of records on scroll') {
    element.all(by.id('users')).map(function (elm) {
        return elm;
    }).then(function (users) {
        expect(users.length).toBe(20);
    });

    // Scroll the table to the bottom to trigger fetching more records

    element.all(by.id('users')).map(function (elm) {
        return elm;
    }).then(function (users) {
        expect(users.length).toBe(40);
    });
};

这样做对吗?

HTML表代码:

代码语言:javascript
运行
复制
<div ng-if="users && users.length > 0" class="table-scroll" ng-infinite-scroll="loadMoreUsers()">
    <table id="users-table" class="table table-hover text-overflow-ellipsis">
        <thead>
            <td class="col1"></td>
            <td id="users-table-name-col" class="col2">User</td>
            <td id="users-table-date-col" class="col3">Birthday</td>
        </thead>
        <tbody ng-repeat="group in users">
            <tr ng-repeat="user in group.users" ng-click="userClicked(user);">
                <td class="col1">
                    <img class="col-xs-1 profile-picture" style="padding:0" ng-src="{{user.profile_picture}}"></td>
                <td class="col2">
                    <div id="user-name"> {{ user.last_name }}, {{ user.first_name }} </div>
                </td>
                <td class="col3">
                    <div id="user-date"> {{user.date}} </div>
                </td>
            </tr>
         </tbody>
     </table>
</div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-06 15:00:04

这样做的目的是在表中找到最新的元素(tr标记),并通过将父元素的scrollTop设置为最后一个元素的offsetTop来滚动到它。

Element.scrollTop属性获取或设置元素内容向上滚动的像素数。元素的scrollTop是一个元素顶部到其最上面可见内容的距离的度量。 HTMLElement.offsetTop只读属性返回当前元素相对于offsetParent节点顶部的距离。

代码语言:javascript
运行
复制
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

    });
});

另见(所用的类似解决方案):

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27794316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档