使用滚动查找所有元素

时间:2015-12-30 15:27:46

标签: javascript selenium selenium-webdriver scroll protractor

找到页面上滚动的所有元素的最可靠和最有效的方法是什么?

目前,我正在考虑使用element.all()filter()比较heightscrollHeight属性值:

element.all(by.xpath("//*")).filter(function (elm) {
    return protractor.promise.all([
        elm.getAttribute("height"),
        elm.getAttribute("scrollHeight")
    ]).then(function (heights) { 
        return heights[1] > heights[0];
    });
});

但我不确定这种方法的正确性和表现。

2 个答案:

答案 0 :(得分:2)

这适用于水平和垂直滚动条。诀窍是检测太宽/太短AND如果计算出的CSS允许你显示滚动条。

//This is PageLoad method from page where I show stickies
    protected void Page_Load(object sender, EventArgs e)
        {
            // Current user id
            String id= Request.QueryString["id"]; 

            // Get stickies from current user
            List<Sticky> stickies = Database.getStickies(id); 

            // Load stickies to screen
            foreach(Sticky s in stickies)
            {
               StickyControl stickyControl = (StickyControl)LoadControl("StickyControl.ascx");
               stickyControl.Text= s.Text;
               stickyControl.Id = s.Id;
               panelStickies.Controls.Add(stickyControl);
            }
        }



//This is delete button in StickyControl.ascx
      protected void btnDeleteSticky_Click(object sender, EventArgs e)
       {
          Database.deleteSticky(Id);           
       }

答案 1 :(得分:1)

它将在body标签内选择溢出和非溢出滚动的元素:

$('body *').filter(function() {
     return ($(this).scrollTop() != 0 || $(this).css('overflow') == 'scroll');
});