How to Drag and Drop in Selenium?
Related Product On This Page Introduction to Drag and Drop in Selenium WebDriverJune 24, 2026 · 4 min read · Tool Comparison
Selenium volunteer a wide range of functionalities for. One website characteristic that must be automatize during testing is Drag and Drop. provides an easy way to drag a web element from one piece of the website and driblet it at another. Key Methods for Performing Drag and Drop in Selenium Example of Automating Drag and Drop in Selenium Using Selenium with Java, quizzer can drag one web element (e.g., file A) and drop it onto another (file B). By leverage theActions class, the automation ensures the interaction mimics real user behavior. Business Impact of Automating Drag and Drop Testing This article discusses how to execute this function in Selenium WebDriver. Few web applications have the power to automate the functionality of drag and pearl, i.e. haul web elements from one end and drop them on a defined country or element. In order to automate the drag and drop activeness of such elements, one can use Selenium Webdriver. This action is execute utilize amousewhen a exploitermotion (drags)a web element from one location and thenplaces (drops)it at another point. SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses. This is a common activeness used in Windows Explorer when moving a file from one booklet to another. Here, the user select a file in the folder, drags it to the desire folder, and drops it. Syntax: In the SeleniumdragAndDropmethod, we pass two parameters: Also Read: The codification snippet below demonstrates the automation of the Drag and Drop activeness program. Try Running Code on Cloud Selenium Grid for Free In this example, the user will drag file A and drop it onto file B as testify below. Read More: Let ’ s now code the like example to see how it works. Try Testing Code on Cloud Selenium Grid for Free Run the code, and see how to automate the Drag and Drop action in Selenium. This is a mutual feature of website and thus needs to be automatize during. This article simplifies the process and helps testers get part with it directly. # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Related Product
How to Drag and Drop in Selenium?
Overview
Introduction to Drag and Drop in Selenium WebDriver
What is Drag and Drop in Selenium?
Actions action = new Actions (driver); action.dragAndDrop (Sourcelocator, Destinationlocator) .build () .perform ();
Code Snippet
//WebElement on which drag and drop operation needs to be performed WebElement fromElement = driver.findElement (By Locator of fromElement); //WebElement to which the above object is dropped WebElement toElement = driver.findElement (By Locator of toElement); //Creating target of Actions form to build composite actions Actions builder = new Actions (driver); //Building a drag and drop activeness Action dragAndDrop = builder.clickAndHold (fromElement) .moveToElement (toElement) .release (toElement) .build (); //Performing the drag and drop action dragAndDrop.perform ();
Difference between Drag and Drop vs Action Class Build
Drag and Drop Action Class Build Selenium provides action.dragandDrop class to travel elements from one end to another Used to move an element from one end to another by working on the element coordinates The user does not have to use build () and perform () actions here to move the element which is an added advantage build() method in Actions classis used to create the chain ofactionor operation to be performed.perform() method in is used toexecutethe chain ofactionmake usingbuild () method Use case: Example of Drag and Drop Action using Selenium and Java
meaning java.util.concurrent.TimeUnit; importation org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; meaning org.openqa.selenium.interactions.Actions; public class DragAndDropExample {public still void main (String [] args) throws InterruptedException {//Set system properties for geckodriver System.setProperty (`` webdriver.gecko.driver '', `` Path_of_the_driver ''); WebDriver driver = new FirefoxDriver (); String URL = `` https: //the-internet.herokuapp.com/drag_and_drop ''; driver.get (URL); // It is incessantly advisable to Maximize the window before performing DragNDrop action driver.manage () .window () .maximize (); driver.manage () .timeouts () .implicitlyWait (10000, TimeUnit.MILLISECONDS); //Actions class method to drag and drop Actions constructor = new Actions (driver); WebElement from = driver.findElement (By.id (`` column-a '')); WebElement to = driver.findElement (By.id (`` column-b '')); //Perform drag and drib builder.dragAndDrop (from, to) .perform (); //verify text changed in to 'Drop here ' box String textTo = to.getText (); if (textTo.equals (`` Dropped! '')) {System.out.println (`` PASS: File is dropped to target as ask '');} else {System.out.println (`` FAIL: File could n't be dropped to target as expected '');} driver.close ();}}Related Guides
Automate This With SUSA
Test Your App Autonomously