我有应该包含10个元素的列表,如果列表包含11个需要显示滚动条的元素,则容器为固定大小。 一切都很好,但是我如何检查滚动是否存在?
cy.get('[data-testid=list-box]')
答案 0 :(得分:1)
您可以获取元素计数,并且如果列表的长度为less than or equal to 10
,请执行一些操作,否则检查visibility
中的scrollbar
。请尝试以下测试,并让我知道
it('Check the length of the list', () => {
cy.get('[data-testid=list-box]')
.then(list => {
const listCount = Cypress.$(list).length;
if(listCount <= 10){
// do some action if the list count is less than 10..
}else{
cy.get('#scrollbar_Id').should('be.visible');
}
});
})
答案 1 :(得分:0)
我是通过使用 jQuery 测量高度和滚动高度来实现的。
it("should force scroll within a large body", () => {
cy.get(".lorem-ipsum-header").click();
cy.get(".section-body")
.should("have.length", 1)
.eq(0)
.should("contain.text", "Lorem ipsum")
.then(($body) => {
cy.wrap($body).invoke("outerHeight").should("eq", 583);
cy.wrap($body).invoke("prop", "scrollHeight").should("eq", 1892);
});
});