Skip to content

Instantly share code, notes, and snippets.

@pragmatictesters
Created December 27, 2018 07:48
Show Gist options
  • Save pragmatictesters/51bc57eb62ad7686deadfd82fb59441c to your computer and use it in GitHub Desktop.
Save pragmatictesters/51bc57eb62ad7686deadfd82fb59441c to your computer and use it in GitHub Desktop.
Selenium WebDriver Examples : Drag and Drop using Actions Class
package com.pragmatic.selenium.examples;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* Selenium WebDriver Examples : Drag and Drop
**/
public class DragAndDropExample {
/**
* Demonstrate use of drag and drop using Actions class
*/
@Test
public void testDragAndDrop(){
WebDriverManager.chromedriver().setup();
WebDriver webDriver = new ChromeDriver();
webDriver.get("http://demosite.pragmatictestlabs.com/Droppable.html");
WebElement sourceElement = webDriver.findElement(By.id("draggableview"));
WebElement targetElement = webDriver.findElement(By.id("droppableview"));
//Dropping an element to a target element
Actions actions = new Actions(webDriver);
actions.dragAndDrop(sourceElement,targetElement)
.build()
.perform();
String message = webDriver.findElement(By.id("droppableview")).getText();
Assert.assertEquals(message, "Dropped!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment