Selenium: Actions drag and drop does not function in chromedriver

Created on 1 Aug 2018  路  5Comments  路  Source: SeleniumHQ/selenium

Meta -

Operating System ->[Microsoft Windows 10 Enterprise] Version 10.0.14393 Build 14393

ChromeDriver -> 2.41.578737

Selenium -> 3.13.0

Chrome -> 68.0.3440.84 (Official Build) (64-bit)

    public static void main(String...args) {
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://the-internet.herokuapp.com/drag_and_drop");
        new Actions(driver).dragAndDrop(driver.findElement(By.id("column-b")), driver.findElement(By.id("column-a"))).build().perform();
    }

When using the actions class dragAndDrop || dragAndDropBy || clickAndHold/MoveToElement/Release within the actions class nothing appears to be happening.

Above is a self contained method which executes the code against the publically available herokuapp. I'm not sure if its something based on my local system, but everything is up to date and the code is having no impact whatsoever.

Most helpful comment

AFAIK - None of the browsers currently produce the HTML5 native drag and drop events (drag, dragStart, dragEnter, etc) when the mouse is depressed, moved, released via WebDriver.

The events produced by the selenium drag and drop actions are mouse_down, mouse_move, mouse_up - so to write code that uses the HTML5 native drag and drop events (and is testable with selenium) you're going to need to use some JS that translates from mouse_down, mouse_move, mouse_up to the HTML5 native drag and drop events. This is why it works on some sites (written to also work with pre HTML5 native drag and drop browsers) and not on others (only using HTML5 native drag and drop events)

All 5 comments

Dup of #3269. See also #6131, #5837, a bunch of others. This is a problem with Chromedriver.

Here is the Chromedriver issue. Last update was a year ago:

ChromeDriver doesn't yet support the Actions commands. The Java language binding translates the Actions requests into corresponding mouse events before sending them to ChromeDriver, however there is no guarantee the translated mouse events are completely equivalent to the original Actions request.

Implementing Actions commands is on our to-do list, but there is no ETA yet.

Since then the issue has been closed and archived, so who knows if they're going to implement a fix.


I tried your snippet with Edge, FF, IE, and Chrome, and couldn't get the drag drop to work in _any_ of them. Am I the only one seeing this?

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import java.util.List;

public class Main {

    public static void main(String[] args) throws InterruptedException
    {

        String driverPath = "C:\\dev\\tools\\selenium\\";

        System.setProperty("webdriver.edge.driver", driverPath + "edgedriver.exe");
        WebDriver driver = new EdgeDriver();

//      System.setProperty("webdriver.firefox.driver", driverPath + "geckodriver.exe");
//      WebDriver driver = new FirefoxDriver();
//
//      System.setProperty("webdriver.explorer.driver", driverPath + "IEDriverServer.exe");
//      WebDriver driver = new InternetExplorerDriver();

//      System.setProperty("webdriver.chrome.driver", driverPath + "chromedriver.exe");
//      WebDriver driver = new ChromeDriver();

        driver.get("https://the-internet.herokuapp.com/drag_and_drop");
        Thread.sleep(1000);
        new Actions(driver).dragAndDrop(driver.findElement(By.id("column-b")), driver.findElement(By.id("column-a"))).build().perform();
        Thread.sleep(1000);

        driver.quit();
    }
}

It's interesting that some things DO drag and drop properly in Chrome. Example:

        driver.get("http://demo.guru99.com/test/drag_drop.html");
        Thread.sleep(1000);
        new Actions(driver).dragAndDrop(driver.findElement(By.xpath("//*[@id='credit2']/a")), driver.findElement(By.xpath("//*[@id='bank']/li"))).build().perform();
        Thread.sleep(1000);

AFAIK - None of the browsers currently produce the HTML5 native drag and drop events (drag, dragStart, dragEnter, etc) when the mouse is depressed, moved, released via WebDriver.

The events produced by the selenium drag and drop actions are mouse_down, mouse_move, mouse_up - so to write code that uses the HTML5 native drag and drop events (and is testable with selenium) you're going to need to use some JS that translates from mouse_down, mouse_move, mouse_up to the HTML5 native drag and drop events. This is why it works on some sites (written to also work with pre HTML5 native drag and drop browsers) and not on others (only using HTML5 native drag and drop events)

@twalpole That's fascinating and perfectly explains what I'm seeing. Here it is in the html5 spec.

Now I'm confused about something else though. I wonder why I haven't seen anything else about this on any issue trackers? Draggable has been supported by all the big browers for 5+ years. Did something change recently to make this a problem?

It's also odd that all the issues I've seen so far just point out Chrome specifically.

@GitSage I would guess people were using compatibility libraries to support older browsers, and only recently have started writing code that relies purely on the HTML5 drag events. I also think the number of people that test with Chrome far exceeds any other browser so you get more reports about that - although I could be wrong on that.

Duplicate of #1365

Was this page helpful?
0 / 5 - 0 ratings