Closed
Description
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
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
vveliev commentedon Dec 10, 2015
dragAndDrop
you may need to run it 2 times , 1st it will focus on the elements second time it will do drag and drop
oflores7 commentedon Dec 11, 2015
I did what you instructed, and ran it twice but still no drag and drop action was performed.
ghost commentedon Dec 22, 2015
having the same problem here. please post the solution here once you find it.
tvdberk commentedon Mar 30, 2016
I've got the same issue here, unable to use the dragAndDrop method nor the clickAndHold + moveToElement + release combination
G-JShaw commentedon Apr 9, 2016
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?
matt-romero00 commentedon Apr 19, 2016
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
lukeis commentedon Jul 20, 2016
also this is the old original issue logged in google code:
SeleniumHQ/selenium-google-code-issue-archive#3604
Properly end HTML5 drag operations when no drop is performed
Properly end HTML5 drag operations when no drop is performed
8 remaining items
ffMathy commentedon Feb 26, 2019
What is the status on implementing this in Selenium?
Herst commentedon Feb 26, 2019
@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).
jasonex7 commentedon Sep 25, 2019
The same works for me on Chrome 77. Thanks!
NotEvenFlinched commentedon Oct 29, 2019
@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
llmartinll commentedon Oct 30, 2019
@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?
NotEvenFlinched commentedon Oct 30, 2019
@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
llmartinll commentedon Oct 31, 2019
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'.
NotEvenFlinched commentedon Oct 31, 2019
@llmartinll
"You would need the difference between the currentPageElement and the targetElement"
Can you please advice how can I calculate or get this difference ?
Naumansh commentedon Jun 22, 2020
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.
glundgren93 commentedon Jun 24, 2020
Any news? 😢🤞
diemol commentedon Jun 26, 2020
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.