← Back to library
Cypressnavigationbeginnerv10+
Scroll to an element
Use .scrollIntoView() to bring an off-screen element into the viewport.
1it('scrolls to the pricing section', () => {
2 cy.visit('/landing');
3
4 // scrollIntoView() scrolls and then yields the element for chaining
5 cy.get('[data-testid="pricing-section"]')
6 .scrollIntoView()
7 .should('be.visible');
8
9 cy.get('[data-testid="pricing-section"] h2')
10 .should('contain.text', 'Pricing');
11});#scroll#scrollIntoView#viewport#off-screen