The dragAndDrop action

The dragAndDrop() method is similar to the dragAndDropBy() method. The only difference being that, instead of moving the WebElement by an offset, we move it on to a target element.

The API syntax for the dragAndDrop() method is as follows:

public Actions dragAndDrop(WebElement source, WebElement target)

The input parameters for the preceding method are the WebElement source and the WebElement target, while the return type is the Actions class.

Let's see a working code example for it. Open the DragAndDrop.html file, which is provided with the book, with two square boxes, as shown in this screenshot:

Here, we can actually ...

Get Selenium WebDriver 3 Practical Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.