Skip to content
CodeKruPro

Scroll with JavaScript

60/70

Scroll with JavaScript

Use page.evaluate to scroll the page, or locator.scrollIntoViewIfNeeded() to scroll to a specific element.

Task:

  1. Navigate to https://testkru.com/Elements/Tables
  2. Scroll down by 300 pixels by calling window.scrollBy() inside page.evaluate()
  3. Read window.scrollY and print whether it is greater than 0 (the exact number depends on the window size, because the browser stops at the bottom of the page)
  4. Use scrollIntoViewIfNeeded() on the employee table
  5. Print that it completed

Expected output:

Scrolled down: true
Table scrolled into view: true