Showing posts with label All ways for DragAndDrop in Selenium Webdriver. Show all posts
Showing posts with label All ways for DragAndDrop in Selenium Webdriver. Show all posts

Friday, 13 December 2013

Webdriver : All Possible ways for DragAndDrop

In WebDriver we have different ways for performing DragAndDrop operations.
Following are the possible ways for handling DragAndDrop

METHOD 1:

// Create Actions object passing in a WebDriver object
            Actions builder = new Actions(driver);

            // Chain some calls together and call build
            Action dragAndDrop = builder.clickAndHold(someElement)
            .moveToElement(otherElement)
            .release(otherElement)
            .build();

            // Perform the actions
            dragAndDrop.perform();
METHOD 2:
            WebElement source = driver.findElement(By.id("draggable"));
            WebElement target = driver.findElement(By.id("droppable"));
            Actions builder = new Actions(driver);
            builder.dragAndDrop(source, target).perform();
            try{
            assertEquals("Dropped!", target.getText());
            } catch (Error e) {
            verificationErrors.append(e.toString());
            }

METHOD 3:
Actions builder = new Actions(driver);
           builder.clickAndHold(SOURCEELEMENT)
           .moveByOffset(10, 50).release().perform(); 
 
METHOD 4:
Action dragAndDrop = builder.dragAndDropBy(SourceElement, 10, 20)
               .build();
                dragAndDrop.perform();




Please do comment for any queries