I have a scenario to drag a tree view item and drop it at a data item in data grid. I have tried Action class with element and action with offset and Mouse Move/Down/Up but nothing working. It clicks on the source element but not drag it to the destination element.
I have tried:
public static void DragAndDrop(this IWebElement source, IWebElement destination)
{
var destinationCenterX = destination.Location.X + destination.Size.Width / 2;
var destinationCenterY = destination.Location.Y + destination.Size.Height / 2;
var action = new Actions(driver); action.MoveToElement(source).Build().Perform();
action.ClickAndHold(source).MoveByOffset(destinationCenterX, destinationCenterY).Build().Perform();
destination.Click(); action.Release().Perform();
}
Or
public static void DragAndDrop(this IWebElement source, IWebElement destination)
{
Actions action0 = new Actions(driver);
action0.ClickAndHold(sourceElement).MoveToElement(destinationElement).Release().Build().Perform();
}
Or
public static void DragAndDrop(this IWebElement source, IWebElement destination)
{
var actions = new Actions(driver);
actions.DragAndDrop(sourceElement,destinationElement).Perform();
}
Or
public static void DragAndDrop(this IWebElement source, IWebElement destination)
{
driver.Mouse.MouseMove(sourceElement.Coordinates);
driver.Mouse.MouseDown(null);
driver.Mouse.MouseMove(destinationElement.Coordinates);
driver.Mouse.MouseUp(null);
Thread.Sleep(TimeSpan.FromSeconds(1));
}
I have tried different way but all the time its clicking and holding the source element but not drag it to destination element.