Perform Drag and Drop 

This action is performed using a mouse when a user moves (drags) a web element from one location and then places (drops) it at another point. This is a common action used in Windows Explorer when moving a file from one folder to another. Here, the user selects a file in the folder, drags it to the desired folder, and drops it.  Selenium provides an easy way to drag a web element from one part of the site and drop it at another. 


import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

public class DragNDrop {

public static void main(String[] args) {

WebDriver driver;
driver= new ChromeDriver();

//Element which needs to drag
WebElement From=driver.findElement(By.xpath(ELEMENT_XPATH));

//Element on which need to drop
WebElement To=driver.findElement(By.xpath(ELEMENT_XPATH));

//Using Action class for drag and drop
Actions act=new Actions(driver);

//Dragged and dropped
act.dragAndDrop(From, To).build().perform();