-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] drag and drop #1094
Comments
The test file comes from mdn: https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/setData References #1094
ChromiumI had a patch that tries to do this years ago. Maybe I can revive it? It ended up touching a lot of layers. WebKitBlocked on WPE not having drag and drop enabled. I'll have to enable it first before deciding how to mock it with playwright. FirefoxI haven't investigated firefox yet. |
Is it possible to drag and drop at this stage? |
Is there a way to drag and drop an element to a particular location on the page? I want to be able to drag and drop either horizontally or vertically by a certain pixels. The current dragAnddrop() method brings the dragger back to its original position as I'm not able to drag it enough to drop it in placeholder. |
Hi ! i wanna know if there is a solution to test drag and drop angular with playwright. |
Any update on this? when drag & drop is planned to be implemented? |
Want to bring this topic up....Are there any progress on this? |
Is there a workaround in Playwright 1.8? |
+1 for this |
2 similar comments
+1 for this |
+1 for this |
For all who struggling with this issue, I found a workaround for it:
This is basically was resolved for puppeteer here: puppeteer/puppeteer#1366, I just copied solution and adjusted a bit for playwright and seems like it works. |
Thanks for this @lind-eduard! I tweaked your workaround to work with Playwright selectors, to include the data transfer object, and drop event. async function dragDrop(page, { origin, destination }) {
const originElement = await page.waitForSelector(origin);
const destinationElement = await page.waitForSelector(destination);
return page.evaluate(async ({ originElement, destinationElement }) => {
const dataTransfer = new DataTransfer();
const getPayload = (element) => {
const rect = element.getBoundingClientRect();
const [x, y] = [rect.x + rect.width / 2, rect.y + rect.height / 2];
return {
bubbles: true,
cancelable: true,
clientX: x,
clientY: y,
dataTransfer,
screenX: x,
screenY: y,
}
};
const originPayload = getPayload(originElement);
const destinationPayload = getPayload(destinationElement);
originElement.dispatchEvent(new MouseEvent('pointerdown', originPayload));
originElement.dispatchEvent(new DragEvent('dragstart', originPayload));
await new Promise((resolve) => setTimeout(resolve, 2000));
destinationElement.dispatchEvent(new MouseEvent('dragenter', destinationPayload));
originElement.dispatchEvent(new DragEvent('dragend', destinationPayload));
destinationElement.dispatchEvent(new DragEvent('drop', destinationPayload));
return { x: destinationPayload.clientX, y: destinationPayload.clientY };
}, { originElement, destinationElement });
} |
Hi, is there any news on this feature? Thanks |
I tried to use the solution from @jperl but it wasn't working. After a bit of debugging i noticed the web application was dependent on the Adding a Improving it even more I would think this is a proper order of events, it might be improved even more
|
Anyone actively working on this? would be awesome to have this :) |
@cscheffauer Yes, just have a look at the linked references of this issue: |
As of today, what's the correct way to implement drag and drop functionality from within a test? I cannot find a working example and it looks like the feature was fixed. EDIT: This is working for me
|
@bsteffensTempus I was missing some clear documentation as well and I implemented this based on the new features: async dragDrop(originSelector: string, destinationSelector: string) {
const originElement = await this.page.waitForSelector(originSelector);
const destinationElement = await this.page.waitForSelector(destinationSelector);
await originElement.hover();
await this.page.mouse.down();
const box = (await destinationElement.boundingBox())!;
await this.page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await destinationElement.hover();
await this.page.mouse.up();
} or this more standalone async dragDrop(page: Page, originSelector: string, destinationSelector: string) {
const originElement = await page.waitForSelector(originSelector);
const destinationElement = await page.waitForSelector(destinationSelector);
await originElement.hover();
await page.mouse.down();
const box = (await destinationElement.boundingBox())!;
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await destinationElement.hover();
await page.mouse.up();
} For reference in 1.13.0 we have page.dragAndDrop() |
i took this and used most of it to work for me, this is sort of janky and isn't very reusable but it can be worked on |
@john-cyndx Drag and drop is an official api since almost a year back now... 🤔 |
Drag and drop is not working in hamburger menu. do we any working around for it ? |
The official inbuilt drag drop didn't work in my case. |
Drag and drop should work with playwright. Using the existing mouse apis should generate working
dragstart
,drag
, anddrop
events. There should also be new APIs to simulate dropping in external content, and to inspect content dragged from the web page.The text was updated successfully, but these errors were encountered: