Simulate Drag and Drop of Files with Playwright

If you’re trying to simulate drag and drop of files in Playwright for testing, you’ll  need to use page.dispatchEvent to accomplish this.

There is a short note on how to do this in the docs:

But this is hardly enough to get it working!

It seems like I’m not the only one.

Good news is that it’s simple:

And if you’re using TypeScript, you’ll need to reference lib.dom by adding this at the top of your TypeScript file:

You may also like...