Selenium

Drag and Drop in Selenium WebDriver using Actions Class – Java Example

Drag and Drop in Selenium WebDriver using Actions Class

By Bhau Automation • Selenium Actions Class Tutorial

🎯 What You Will Learn

  • What is Drag and Drop in Selenium WebDriver
  • How to use Actions class in Selenium
  • How to perform dragAndDrop() operation
  • Mouse actions click(), doubleClick(), contextClick()
  • Practical Java example for drag and drop automation
💡 Practice Selenium automation using our demo website: https://www.bhauautomation.com → Services → Selenium Automation Practice Page.

📌 What is Drag and Drop in Selenium?

Drag and Drop is a common user interaction where an element is dragged from one location and dropped into another location on the web page.

In Selenium WebDriver, drag and drop functionality can be implemented using the Actions class.

💻 Drag and Drop Selenium Java Example

Actions actions = new Actions(driver);

WebElement source = driver.findElement(By.id("dragElement"));

WebElement target = driver.findElement(By.id("dropElement"));

actions.dragAndDrop(source, target).perform();

🔧 Alternative Drag and Drop Method

Actions actions = new Actions(driver);

actions.clickAndHold(source)
       .moveToElement(target)
       .release()
       .perform();

🖱 Important Mouse Actions in Selenium

  • click() – Click action
  • doubleClick() – Double click action
  • contextClick() – Right click action
  • dragAndDrop() – Drag element and drop to target

🎯 Real-World Use Cases

  • Testing drag-and-drop file upload UI
  • Automating kanban boards like Trello
  • Moving widgets in dashboards
  • Testing interactive UI components

❓ Selenium Interview Questions

Q: Which class is used to perform drag and drop in Selenium?

A: The Actions class using the method dragAndDrop().

Q: What is the syntax for drag and drop?

A: actions.dragAndDrop(source, target).perform();

🎥 Watch the Complete Video Tutorial

👉 Watch on YouTube: Drag and Drop in Selenium WebDriver using Actions Class

🎓 Key Takeaways

  • Actions class is used for advanced mouse interactions
  • dragAndDrop() method moves element from source to target
  • Useful for testing modern interactive UI applications
  • Important Selenium automation interview topic

🚀 Created with ❤️ by Bhau Automation

Back to All Articles