Drag and drop gets executed but its not getting performed - webdriver

10,144

Try this code:

 Actions ac = new Actions(driver);
 ac.dragAndDrop(source element, target element);
 ac.build().perform();

It will click-and-hold at the location of the source element, moves to the location of the target element, then releases the mouse.

Or

 Actions ac = new Actions(driver);
 ac.dragAndDropBy(source element, xOffset, yOffset);
 ac.build().perform();

It will click-and-hold at the location of the source element, moves by a given offset, then releases the mouse.

Or

    Actions ac = new Actions(driver);
    ac.clickAndHold(onElement);
    ac.moveToElement(toElement); or ac.moveToElement(toElement, xOffset, yOffset);
    ac.build().perform();

It will do the action of the above two code.

I write this code on Java. You can convert in to your specified language.

Refereed from Actions.

Share:
10,144
Anand S
Author by

Anand S

Updated on June 05, 2022

Comments

  • Anand S
    Anand S almost 2 years

    I have tried these two codes , it get executed but the action does not get performed ,Can any one tell me why?

    //Type one approach
    Actions action = new Actions(Browser.Driver);
    IWebElement sourceElement = Browser.Driver.FindElement(By.XPath(Filexpath));
    IWebElement targetElement = Browser.Driver.FindElement(By.XPath(NewXpath));
    
    //Type two approach 
    Actions Sourcebuilder = new Actions(Browser.Driver);
    Actions SourceAction = Sourcebuilder.ClickAndHold(sourceElement);
    Sourcebuilder.Build();
    SourceAction.Perform();
    
    
    
    /// move and drop
    Actions builder = new Actions(Browser.Driver);
    Actions action = builder.MoveToElement(targetElement);
    builder.Release(targetElement);
    builder.Build();
    action.Perform();
    

    Thanks in advance