Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

drake
drake

Posted on

Playwright滑动页面的注意点

有多种方式能够实现页面的滑动,而其中最简单的就是playwright调用自己模拟鼠标滚轮的接口方法

  • 模拟鼠标滚轮存在一个注意点,否则将会失效

  • 示例代码:

表示每一次执行滚动3000个像素(从下往上翻)

await page.mouse.wheel(0, 3000)
Enter fullscreen modeExit fullscreen mode
  • 在执行上面的代码前必须要线将光标移到屏幕中央,否则上述代码无法生效:
    async def move_to_center(self, page):        # 获取页面视口大小        viewport = page.viewport_size        center_x = viewport["width"] / 2        center_y = viewport["height"] / 2        # 移动鼠标到屏幕中央        await page.mouse.move(center_x, center_y)
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

生活唯一不可或缺的是学习
  • Location
    Dubai
  • Education
    master
  • Joined

More fromdrake

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp