0

I'm new to puppeteer and browser automation as a whole. I'd like to emulate a swiping event. I've done a lot of research, I don't event know if it's event possible, I read the puppeteer documentation but would still not find any useful help.

I tried using Webapi dispatchEvent https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent but I get the isTrusted : false so it's not working on the target website. I learnt puppeteer is able to bypass that like this, hence I'd like to do the swiping with puppeteer.

enter image description here

Any assistance will be greatly appreciated!

  • This is rather broad. What page are you working with and where's your code so far? Have you tried [How to simulate a drag and drop action in puppeteer?](https://stackoverflow.com/questions/49772472/how-to-simulate-a-drag-and-drop-action-in-puppeteer)? Thanks. – ggorlen Sep 26 '22 at 13:55

1 Answers1

1

This works for me, hope it helps

const element = await page.$('.selector');
const elboundingBox = await element.boundingBox();
const xWidth = targetboundingBox.width / 2;
const yHeight = targetboundingBox.height / 2;

await page.mouse.move( elboundingBox.x + xWidth, elboundingBox.y + xHeight);
await page.mouse.down();
await page.mouse.move(newTargetLeft, newTargetTop, { steps: 1 });
await page.mouse.up();

Replace newTargetLeft and newTargetTop with your new x and y positions respectively. Changing the steps sets the how immediate the move should occur

Getrou
  • 11
  • 2