DRAG AND DROP

  

package mypackage;

 

import java.util.concurrent.TimeUnit;

 

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.interactions.Actions;

 

public class DrafAndDrop {


public static void main(String[] args) {

System.setProperty("webdriver.gecko.driver","C:\\Browser\\geckodriver.exe");

WebDriver driver=new FirefoxDriver();

driver.manage().window().maximize();

driver.get("https://www.seleniumeasy.com/test/drag-and-drop-demo.html");

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

                   

Actions action=new Actions(driver);

                   

WebElement drag=driver.findElement(By.xpath("//span[text()='Draggable 1']"));

WebElement drop=driver.findElement(By.id("mydropzone"));


action.clickAndHold(drag).moveToElement(drop).release(drop).build().perform();

driver.quit();

}

}

shortcut

action.dragAndDrop(drag, drop).perform();