1

I am trying to drag an element into another element using Selenium WebDriver but it's not working. We tried with different solutions as mentioned below :

Application was built on Anjular4

WebElement From = (driver.findElement(By.xpath("")));
WebElement To = (driver.findElement(By.xpath("//*[@id='avpContainer']"));
Actions builder = new Actions(driver);
builder.clickAndHold(From).moveToElement(To).click(To).release().build().perform();





WebElement From = (driver.findElement(By.xpath("")));
WebElement To = (driver.findElement(By.xpath("//*[@id='avpContainer']"));
Actions builder = new Actions(driver);
builder.clickAndHold(From).release(To).build().perform();

WebElement From = (driver.findElement(By.xpath("")));
WebElement To = (driver.findElement(By.xpath("//*[@id='avpContainer']"));
Actions builder = new Actions(driver);
builder.dragAndDrop(From, To).build().perform();

//Setup robot
Robot robot = new Robot();
robot.setAutoDelay(50);
//Maximized browser:
robot.keyPress(KeyEvent.VK_F11);
Thread.sleep(2000);
WebElement dragElement = d.findElement('drag element');
Actions builder = new Actions(d);
builder.dragAndDropBy(dragElement,x, y).build().perform();

Can anyone help to resolve this issue.

  • Check this https://stackoverflow.com/questions/14210051/how-to-automate-drag-drop-functionality-using-selenium-webdriver-java – Vincent Feb 12 '18 at 11:16
  • Try giving perform() in the next line like below, sometime it worked for me,.....builder.clickAndHold(From).moveToElement(To).click(To).release().build(); builder.perform(); – Vincent Feb 12 '18 at 11:18
  • @Vincent We also tried as suggested by you, not working for us If the application is build on HTML5 drag and drop feature using selenium will not been supported? – naveen kumar Feb 14 '18 at 16:55

2 Answers2

0
WebElement From = driver.findElement(By.xpath(""));
WebElement To = driver.findElement(By.xpath(""));
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(From)
.moveToElement(To)
.release(To)
.build();
dragAndDrop.perform();
Vincent
  • 484
  • 4
  • 6
  • 21
0

Drag and Drop functionality won't work, if application is built on HTML5.

So, we can make this work with the support of draganddrop.js