org.openqa.selenium.interactions.Actions
When using the above class from the selenium library, the method dragAndDrop(WebElement source, WebElement target) does not work. I have tried executing it multiple times with no luck. Attached is my code to use the drapAndDrop method.
DragAndDropIssue.txt
dragAndDrop
you may need to run it 2 times , 1st it will focus on the elements second time it will do drag and drop
I did what you instructed, and ran it twice but still no drag and drop action was performed.
having the same problem here. please post the solution here once you find it.
I've got the same issue here, unable to use the dragAndDrop method nor the clickAndHold + moveToElement + release combination
I'm having a similar issue using Selenium.WebDriver v2.53.0 and Firefox v45.0.1 using the C# code below. This is moving Backgrid table columns around. Was working in v2.44.0.
Anyone experiencing something similar?
var actionBuilder = new Actions(Browser);
var dragAction = actionBuilder
.ClickAndHold(columnToDragElement)
.MoveToElement(dragToColumnElement)
.Release()
.Build();
dragAction.Perform();
I believe that the issue is related to HTML5. This is a solution that I found so far: http://elementalselenium.com/tips/39-drag-and-drop
also this is the old original issue logged in google code:
https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/3604
Is there any workaround for moving in coordinates, not to the element?
Is there any workaround for moving in coordinates, not to the element?
Have you tried triggering the mouseMove command twice? That seems to do the trick for me. Although FirefoxDriver works as aspected so my workaround is issuing the move-command twice if a non-firefox driver is detected.
var actionBuilder = new Actions(Browser);
var dragAction = actionBuilder
.ClickAndHold(columnToDragElement)
.moveByOffset(xOff, yOff)
.moveByOffset(xOff, yOff)
.Release()
.Build();
dragAction.Perform();
What is the status on implementing this in Selenium?
@ffMathy Do you mean Drag and Drop using the HTML5 drag and drop API or Drag and Drop using a particular JS library? In any case, it's hardly something which has to do with Selenium (the WebDriver client) but rather the browsers interacted with (or in the case of HTML5 DnD the WebDriver protocol standard).
Have you tried triggering the mouseMove command twice? That seems to do the trick for me.
The same works for me on Chrome 77. Thanks!
@jasonex7 @llmartinll
I tried may be all solutions discovered, including yours, but for me drag and drop works only if I move mouse during auto-test execution )
Chrome 76
@Wonderio619 What are you trying to do, and what do you mean by 'auto-test execution'?
I think I remember a couple of months ago something got changed/fixed so you don't have to issue the move command twice. However, looking at my own code it seems the drag and drop by offset might stil cause problems for chrome.
Can you try if something like this works for you?
var actionBuilder = new Actions(Browser);
var dragAction = actionBuilder
.ClickAndHold(columnToDragElement)
.moveByOffset(10, 0)
.moveByOffset(-10, 0)
.moveByOffset(xOff, yOff)
.Release()
.Build();
dragAction.Perform();
@llmartinll
I'm trying to drag n drop element on another element, and only if I physically moving mouse during drag n drop part, only then this drag n drop code works
With your code I have "move target out of bounds" exception
string selector = AttachmentPageSelector.Replace("NUMBER", pageId);
var currentPageElement = WebBrowser.WebDriver.FindElement(By.XPath(selector));
int xOff = LinkedPagesContainer.Element.Location.X;
int yOff = LinkedPagesContainer.Element.Location.Y;
var dragAction = actions.ClickAndHold(currentPageElement).MoveByOffset(10, 0).MoveByOffset(-10, 0).MoveByOffset(xOff, yOff).Release().Build();
dragAction.Perform();
You are using the destination's X,Y coordinates as an offset, that won't work. You would need the difference between the currentPageElement and the targetElement. But, I would use the .MoveToElement functionality. And maybe trigger it twice.
I think you're having 'general' issues getting your code to work. Maybe I'm wrong, but it seems more like a stackoverflow question and less like a 'selenium doesn't work as expected question'.
@llmartinll
"You would need the difference between the currentPageElement and the targetElement"
Can you please advice how can I calculate or get this difference ?
Is there any fix to this issue? The drag and drop does not work both on chrome and firefox. i have tried all suggested solutions but nothing works.
Any news? 馃槩馃
Apologies for the late reply.
I tried to reproduce the original issue and I got the code to work. I pushed the code to this repository in case someone wants to have a look: https://github.com/diemol/selenium-issues/blob/master/selenium/issue-1365/src/test/java/DragAndDropActions.java
Here is the code running:

I also saw that the issue has several comments reporting other different issues. Therefore, if you are still having an issue with the most recent version of Selenium and/or the Selenium 4 Alphas, please create a new issue and provide all the required information.
Most helpful comment
@Wonderio619 What are you trying to do, and what do you mean by 'auto-test execution'?
I think I remember a couple of months ago something got changed/fixed so you don't have to issue the move command twice. However, looking at my own code it seems the drag and drop by offset might stil cause problems for chrome.
Can you try if something like this works for you?