How to drag and drop elements in selenium webdriver?

In this video we will see the drag and drop functionality using selenium werbdriver. How to automate the process of dragging one element on other element using selenium.

I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com

Complete source code:

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

public class DemoDragAndDrop {

 public static void main(String[] args) throws InterruptedException {
  // TODO Auto-generated method stub
  
  System.setProperty("webdriver.chrome.driver", "C:\\work\\Selenium\\chromedriver_win32_version98\\chromedriver.exe");
  WebDriver driver = new ChromeDriver();
  
  driver.manage().window().maximize();
  driver.get("http://www.dhtmlgoodies.com/submitted-scripts/i-google-like-drag-drop/index.html");
  
  
  
  WebElement source = driver.findElement(By.xpath("//h1[text() = 'Block 1']"));
  
  WebElement target = driver.findElement(By.xpath("//h1[text() = 'Block 3']"));
  
  Actions act = new Actions(driver);
  
  act.dragAndDrop(source, target).perform();
   //Thread.sleep(3000);
  
  driver.close();
  
  

 }

}

Leave a Reply

%d bloggers like this:
Available for Amazon Prime