Skip to content
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

Actions drag and drop method #1365

Closed
oflores7 opened this issue Dec 10, 2015 · 20 comments
Closed

Actions drag and drop method #1365

oflores7 opened this issue Dec 10, 2015 · 20 comments
Labels

Comments

@oflores7
Copy link

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

@vveliev
Copy link

vveliev commented 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
Copy link
Author

I did what you instructed, and ran it twice but still no drag and drop action was performed.

@ghost
Copy link

ghost commented Dec 22, 2015

having the same problem here. please post the solution here once you find it.

@tvdberk
Copy link

tvdberk commented Mar 30, 2016

I've got the same issue here, unable to use the dragAndDrop method nor the clickAndHold + moveToElement + release combination

@G-JShaw
Copy link

G-JShaw commented 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?

var actionBuilder = new Actions(Browser);
var dragAction = actionBuilder
    .ClickAndHold(columnToDragElement)
    .MoveToElement(dragToColumnElement)
    .Release()
    .Build();
dragAction.Perform();

@matt-romero00
Copy link

matt-romero00 commented 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
Copy link
Member

lukeis commented Jul 20, 2016

also this is the old original issue logged in google code:

SeleniumHQ/selenium-google-code-issue-archive#3604

@Mogost
Copy link

Mogost commented Jul 11, 2017

Is there any workaround for moving in coordinates, not to the element?

@llmartinll
Copy link

llmartinll commented Jan 12, 2019

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();

@ffMathy
Copy link

ffMathy commented Feb 26, 2019

What is the status on implementing this in Selenium?

@Herst
Copy link
Contributor

Herst commented 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
Copy link

jasonex7 commented Sep 25, 2019

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!

@NotEvenFlinched
Copy link

@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
Copy link

llmartinll commented 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?

var actionBuilder = new Actions(Browser);
var dragAction = actionBuilder
    .ClickAndHold(columnToDragElement)
    .moveByOffset(10, 0)
    .moveByOffset(-10, 0)
    .moveByOffset(xOff, yOff)
    .Release()
    .Build();
dragAction.Perform();

@NotEvenFlinched
Copy link

NotEvenFlinched commented 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

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();

@llmartinll
Copy link

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
Copy link

@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
Copy link

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
Copy link

Any news? 😢🤞

@diemol
Copy link
Member

diemol commented 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:
issue-1365

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.

@diemol diemol closed this as completed Jun 26, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Sep 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests