如何滚动到 Puppeteer 中提供的元素?

Raj*_*h G 0 puppeteer

我需要滚动到 puppeteer 中的元素。如何实现这一目标?我尝试模拟移动设备来检查响应能力

mbi*_*bit 5

这是一种方法:

await page.evaluate(() => document.querySelector(selector).scrollIntoView());
Run Code Online (Sandbox Code Playgroud)

在这里阅读更多相关内容。

您还可以尝试:

await page.hover(selector);
Run Code Online (Sandbox Code Playgroud)

它在幕后使用相同的功能。