【问题标题】:How to emulate swipe on puppeteer如何在 puppeteer 上模拟滑动
【发布时间】:2022-09-26 16:45:39
【问题描述】:

作为一个整体,我是 puppeteer 和浏览器自动化的新手。我想模拟一个滑动事件。我做了很多研究,我不知道这是否可能发生,我阅读了 puppeteer 文档但仍然找不到任何有用的帮助。

我尝试使用 Webapi dispatchEvent https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent 但我明白了isTrusted : 假所以它在目标网站上不起作用。我了解到 puppeteer 能够像这样绕过它,因此我想用 puppeteer 进行刷卡。

任何帮助将不胜感激!

    标签: javascript puppeteer


    【解决方案1】:

    这对我有用,希望它有帮助

    const element = await frameContent.$('.selector');
    const elboundingBox = await element.boundingBox();
    const xWidth = targetboundingBox.width / 2;
    const yHeight = targetboundingBox.height / 2;
    
    await page.mouse.move( / 2, 565.3125);
    await page.mouse.down();
    await page.mouse.move(newTargetLeft, newTargetTop, { steps: 1 });
    await page.mouse.up();
    

    将 newTargetLeft 和 newTargetTop 分别替换为新的 x 和 y 位置。更改步骤设置了移动应该如何立即发生

    【讨论】:

      猜你喜欢
      • 2018-09-21
      • 2020-02-29
      • 2020-06-04
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多