-1

I have tried the below code but it seems it is not working.

driver.findElement(By.xpath(xpath)).then(function (element1) {              
    driver.findElement(By.xpath(xpath)).then(function (element2) {                                                  
      .then(() => driver.actions().dragAndDrop(element1,element2).perform())
    })
})
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Faheem
  • 111
  • 6

1 Answers1

0

This is an overly complicated code. You can simply use the dragAndDrop() method to achieve this in this way -

browser.actions().dragAndDrop(elem, target).perform();

where elem is the source element and target is the target element.

Edit 1 : OP mentioned that the webpage is an Angular webpage. I have experienced persistent issues automating this scenario in both Java Bindings, and also using Protractor.

There are several discussion forums, where dragAndDrop issues have been discussed. One of them is this, another is this.

While the first one is closed and still not sure if it got solved. The latter had a luck with the code mentioned in the post, but my implementation failed to do anything. So I'm not sure if it works.

Also, you can try this repo, where I tried one of the solutions, using a custom JS file to achieve drag and drop in HTML5 for Angular applications.

demouser123
  • 4,108
  • 9
  • 50
  • 82