Dragging and dropping a Widget control in a web page can be done using Selenium advanced
interactions namespace (package in Java), here is the fully qualified namespace
using OpenQA.Selenium.Interactions;
This can be done using
Actions class. The
Actions class has different methods like
ClickAndHold, MoveToElement, Click etc as shown.
Well, in order to drag and drop a Element from one location to another, its always a wise idea to specify the destination Element where the source element has to be moved, since specifying the co-ordinate will always end-up having miserable results.
To do so following has to be done
- Hold the source
- Move the element
- Release the element
Hence the coding will look like this
Actions action = new Actions(driver);
IAction dragdrop = action.ClickAndHold(element).MoveToElement(toElement).Release(toElement).Build();
dragdrop.Perform();
This does exactly what we are expecting, the drag and drop operation.
Thanks,
Karthik KK