
- Selenium Tutorial
- Selenium - Home
- Selenium - Overview
- Selenium - IDE
- Selenium - Environment Setup
- Selenium - Remote Control
- Selenium - Selenese Commands
- Selenium - WebDriver
- Selenium - Locators
- Selenium - User Interactions
- Selenium - Test Design Techniques
- Selenium - TestNG
- Selenium - Grid
- Selenium Useful Resources
- Selenium - Quick Guide
- Selenium - Useful Resources
- Selenium - Automation Practice
- Selenium - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Selenium - Drag and Drop
As a tester, you might be in a situation to perform a 'Drag & drop' operation. We will perform a drag and drop operation by picking up a tree grid that is available for us on http://www.keenthemes.com/preview/metronic/templates/admin/ui_tree.html. In the example, we would like to drag an element 'Disable Node' from 'initially open' folder to 'Parent Node' Folder.

Example
import java.util.concurrent.TimeUnit; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.interactions.Action; public class webdriverdemo { public static void main(String[] args) throws InterruptedException { WebDriver driver = new FirefoxDriver(); //Puts a Implicit wait, Will wait for 10 seconds before throwing exception driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Launch website driver.navigate().to("http://www.keenthemes.com/preview/metronic/templates/admin/ui_tree.html"); driver.manage().window().maximize(); WebElement From = driver.findElement(By.xpath(".//*[@id='j3_7']/a")); WebElement To = driver.findElement(By.xpath(".//*[@id='j3_1']/a")); Actions builder = new Actions(driver); Action dragAndDrop = builder.clickAndHold(From).moveToElement(To).release(To).build(); dragAndDrop.perform(); driver.close(); } }
Output
After performing the drag-drop operation, the output would be as shown below.

selenium_user_interactions.htm
Advertisements