0

I have tried various options, but have been unable to simulate a mouse click to drag an element from one position to another in a browser using Selenium. When the test runs, I see the element get selected, but it does not move to the specified drop point. Any suggestions or insights are greatly appreciated!

Here's how I defined the function in my latest attempt (variations on this theme also tried and failed):

private void dragAndDrop(WebElement dragPoint, WebElement dropPoint, WebDriver driver) {
    Actions builder = new Actions(driver);
    builder.clickAndHold(dragPoint).perform();
    builder.pause(Duration.ofSeconds(1));
    builder.moveByOffset(10,0).perform(); 
    builder.moveToElement(dropPoint).perform();
    builder.moveByOffset(10,0).perform(); 
    builder.pause(Duration.ofSeconds(1));
    builder.release();
    builder.build();
    builder.perform();
}

Also tried the following (same result):

private void dragAndDrop(WebElement dragPoint, WebElement dropPoint, WebDriver driver) {
    Actions builder = new Actions(driver);
    Action dragAndDrop = builder.dragAndDrop(dragPoint, dropPoint).build();
    dragAndDrop.perform();
}

In the test, the 2 elements are identified uniquely using xpath and the function is called:

WebElement dragPoint = driver.findElement(By.xpath(".../div[3]/...(etc.)/div[@class='rst__moveHandle']"));
WebElement dropPoint = driver.findElement(By.xpath(".../div[5]/...(etc.)/div[@class='rst__moveHandle']"));

dragAndDrop(dragPoint, dropPoint, driver);

Relevant libraries:

react-beautiful-dnd: https://github.com/atlassian/react-beautiful-dnd

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
toasty
  • 228
  • 2
  • 7
  • Seems to be an problem as there are a couple of other questions https://stackoverflow.com/questions/53842465/actionchain-drag-and-drop-with-on-react-beautiful-dnd-page-in-python and https://stackoverflow.com/questions/50295160/how-to-test-drag-and-drop-with-selenium-on-the-react-dnd-treeview-library . I did find this helper javascript library https://gist.github.com/smooney/d8b0e7b5f7b89d74bb7d which you could try to integrate. – elworthy Feb 04 '19 at 10:18
  • Thank you for the suggestion, elworthy. So far, I have not been able to get the javascript library to work. – toasty Feb 08 '19 at 06:11

0 Answers0