首页 > 解决方案 > Get the very last row in a table, although it isn't scrolled into current sight

问题描述

I have a table which contains many rows. Only the nth-oldest rows are visible. The newer rows are hidden and one has got to use a scrollbar to move them into sight.

I have written the following Cypress-statement:

cy.get("span.class1.class2").last().click();

It returns the last row, which is visible, when the view becomes shown. Marked red in the screenshot.

enter image description here

But what I like to have is the very last row in the table. Marked blue.

enter image description here

Is that possible with a simple Cypress-statement?

Or do I have to move the scrollbar down first? If so: How can I scroll downwards using Cypress?

标签: javascriptintegration-testingcypress

解决方案


获取该parent表的类,您可以尝试使用scrollTo()选项。

赛普拉斯文档: https ://docs.cypress.io/api/commands/scrollto.html#Syntax

例子:

cy.scrollTo(0, 500)                     // Scroll the window 500px down
cy.get('.sidebar').scrollTo('bottom')   // Scroll 'sidebar' to its bottom

还有另一个选项称为.scrollIntoView(),但我认为在您的情况下 scrollTo() 可能会有所帮助。


推荐阅读