How to automate drag & drop functionality using Selenium WebDriver Java

user1891145 picture user1891145 · Jan 8, 2013 · Viewed 127.3k times · Source

How to automate drag & drop functionality using Selenium WebDriver in java?

Answer

r-sal picture r-sal · Jan 8, 2013

There is a page documenting Advanced User Interactions; which has a lot of great examples on how to generate a sequence of actions, you can find it here

// Configure the action
Actions builder = new Actions(driver);

builder.keyDown(Keys.CONTROL)
   .click(someElement)
   .click(someOtherElement)
   .keyUp(Keys.CONTROL);

// Then get the action:
Action selectMultiple = builder.build();

// And execute it:
selectMultiple.perform();   

or

Actions builder = new Actions(driver);

Action dragAndDrop = builder.clickAndHold(someElement)
   .moveToElement(otherElement)
   .release(otherElement)
   .build();

dragAndDrop.perform();