Performing drag-and-drop operations
Selenium WebDriver implements Selenium RC's dragAndDrop
command using the Actions
class. As seen in earlier recipes, the Actions
class supports advanced user interactions such as firing various mouse and keyboard events. We can build simple or complex chains of events using this class.
In this recipe, we will use the Actions
class to perform drag-and-drop operations.
How to do it...
Let's implement a test that will perform a drag-and-drop operation on a page using the Actions
class:
@Test public void testDragDrop() { driver.get("http://cookbook.seleniumacademy.com/DragDropDemo.html"); WebElement source = driver.findElement(By.id("draggable")); WebElement target = driver.findElement(By.id("droppable")); Actions builder ...
Get Selenium Testing Tools Cookbook - 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.