How can I scroll down the page in playwrightTest?

Viewed 23

I am writing a code using playwright test and its working fine in debug mode but normally its not able to find the element because not able to scroll down the page., I have tried using scrollintoview and mouse.move funtion as well.

2 Answers

You can use locator.focus() instead which will do the scrolling for you.

await locator.focus();

If you want to perform the click operation on that element, then page.click() function internally scroll into view to the target element.

Reference: https://playwright.dev/docs/api/class-page#page-click

page.click(selector[, options])

This method clicks an element matching selector by performing the following steps:

  1. Find an element matching selector. If there is none, wait until a matching element is attached to the DOM.
  2. Wait for actionability checks on the matched element, unless force option is set. If the element is detached during the checks, the whole action is retried.
  3. Scroll the element into view if needed.
  4. Use page.mouse to click in the center of the element, or the specified position.
  5. Wait for initiated navigations to either succeed or fail, unless noWaitAfter option is set.
Related