'How to perform drag and drop on HTML5 element using Selenium 3.141.59 + Java

I am unable to perform drag and drop on HTML5 element using Selenium 3.141.59 + java (1.8). I have tried other solutions(through JavaScriptExecutor) as well which are mentioned in this group. But no solutions are working. Could you please help me to provide a concrete solution for my issue.

I am using Selenium(3.141.59) + Java (1.8) + Cucumber Framework + Selenium Grid (4)

I have followed the discussion but it is for python but I need a solution in Java.



Solution 1:[1]

To perform dragAndDrop() as an example within the website you need to induce WebDriverWait for the elementToBeClickable() and you can use the following locator strategies:

  • Using XPATH:

    driver.get("http://www.dhtmlgoodies.com/scripts/drag-drop-custom/demo-drag-drop-3.html")
    WebElement  drag = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[starts-with(@id, 'box') and text()='Rome']")));
    WebElement  drop = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[starts-with(@id, 'box') and text()='South Korea']")));
    new Actions(driver).dragAndDrop(drag, drop).build().perform();
    

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1