2

I want to simulate a drag within an element using spectron/electron. I tried 2 ways:

await client.moveToObject(selector, fromX, fromY);
await client.buttonDown(0);
await client.moveToObject(selector, toX, toY);
await client.buttonUp(0);

and

await webContents.sendInputEvent({
  type: "mouseMove",
  x: fromX,
  y: fromY
});
await webContents.sendInputEvent({
  type: "mouseDown",
  button: "left",
  x: fromX,
  y: fromY
});
await webContents.sendInputEvent({
  type: "mouseMove",
  button: "left",
  x: toX,
  y: toY
});
await webContents.sendInputEvent({
  type: "mouseUp",
  button: "left",
  x: toX,
  y: toY
});

I also tried plenty different versions/combinations of the above (including e.g. movementX & movementY). I can't use the actions api (my driver does not implement it yet).

With all my approaches, nothing at all happens (no errors neither). Is there a way to implement drag (not drag&drop, it's just within one element)?

Michael Hopfner
  • 133
  • 1
  • 10
  • You might miss the "clickCount" field when using sendInputEvent. – hiitiger Nov 30 '18 at 14:57
  • @hiitiger can you elaborate? What does clickCount mean in this context? – Michael Hopfner Dec 03 '18 at 06:49
  • https://github.com/electron/electron/blob/master/docs/api/web-contents.md#contentssendinputeventevent webContents.sendInputEvent({ type: "mouseDown", button: "left", x: fromX, y: fromY, clickCount: 1 }); and I don't think sendInputEvent return a promise so don't use await on it. – hiitiger Dec 03 '18 at 07:35
  • This and many variations of it don't help. sendInputEvent does indeed return a promise (I know the typing says otherwise, but console.log tells the truth). – Michael Hopfner Dec 03 '18 at 09:56

0 Answers0