Playwright滑动页面的注意点
drake
Posted on November 23, 2024
有多种方式能够实现页面的滑动,而其中最简单的就是playwright调用自己模拟鼠标滚轮的接口方法
模拟鼠标滚轮存在一个注意点,否则将会失效
示例代码:
表示每一次执行滚动3000个像素(从下往上翻)
await page.mouse.wheel(0, 3000)
- 在执行上面的代码前必须要线将光标移到屏幕中央,否则上述代码无法生效:
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)
💖 💪 🙅 🚩
drake
Posted on November 23, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
undefined I absolutely love when CSS gets new features (Even though it usually takes me years to remember to use them 😄)
November 27, 2024