Search code examples
javaseleniumtestingdrag

Click and Drag Selenium (chrome webdriver) is not dragging, but will click and hold


So I am trying to automated a list element that can be clicked, and dragged to different portions of the ol elements, and then saved. But the test will oly go as far as to hold the element. it will not move by offset, and it will not move to the target element.

Chrome webdriver, Java/Selenium

public void clickAndDragListElement() {
    Actions hold = new Actions(driver);
    hold.clickAndHold(targetHoldElement)
        .moveToElement(targetDestinationElement)
        .release(targetHoldElement)
        .build()
        .perform();
}

(WebElements are defined outside the element)


Solution

  • new Actions(driver)
                    .moveToElement(source)
                    .pause(Duration.ofSeconds(1))
                    .clickAndHold(source)
                    .pause(Duration.ofSeconds(1))
                    .moveByOffset(1, 0)
                    .moveToElement(destination)
                    .moveByOffset(1, 0)
                    .pause(Duration.ofSeconds(1))
                    .release().perform();