Friday, 21 February 2014

How to perform drag and drop operation in selenium webdriver in Java?

We can drag and drop the elements using Actions class in selenium webdriver in Java.
Below class/Interface must be imported before performing drag and drop in Selenium Webdriver.

import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

//create Actions object
Actions builder = new Actions(driver);

//create a chain of actions to move element e1 to e2
Action dragAndDropAction = builder
  .clickAndHold(e1)
  .moveToElement(e2)
  .release(e2)
  .build();


//perform drag and drop action

 dragAndDropAction.perform();

What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

1 comment:

  1. Action dragAndDropAction = builder
    .clickAndHold(e1)
    .moveToElement(e2)
    .release(e2)
    .build();


    //perform drag and drop action

    dragAndDropChain.perform()


    you used dragAndDropChain istead of dragAndDropAction. p lease correct me if i understood wrong...:)

    ReplyDelete

Buy Best Selenium Books

Contributors