Selenium Assignment – 7 – Drag and Drop

In this Selenium Assignment, we will be practicing iframe handling, CSS property verification and a mouse hover operation – drop and drop operation using actions class.


  • Open a browser of your choice for example – Chrome Browser.
  • Navigate to webpage.

drag and drop using selenium

  • Consider “Drag me to my target” as a source and “Drop here” as a target.
  • Write a code to perform drag and drop operation from source to target.

Drag and Drop operation

  • After drag and drop verify the operation is successfully by checking the color property of CSS and also verify text change. (Use assert statement to verify that color and text are as expected.)

Try this scenario and send us the code for feedback and assessment, or if you have any questions, queries or comments. Feel free to write us We will be back soon with the next assignment.

Till then, Keep Learning 🙂

Update — Please find the code below —

package day2;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

public class DragAndDrop {

	public static void main(String[] args) throws InterruptedException {

		ChromeDriver driver;

		System.setProperty("", "D:/Software/chromedriver_75/chromedriver.exe");

		driver = new ChromeDriver();



		WebElement webFrame = driver.findElement(By.className("demo-frame"));
		WebElement source = driver.findElement("draggable"));
		WebElement target = driver.findElement("droppable"));
		Actions action = new Actions(driver);
		String colourBeforeDnD = target.getCssValue("color");
		//action.dragAndDrop(source, target).build().perform();

		String colorAfterDnD = target.getCssValue("color");
		System.out.println("Color before Drag and Drop : "+ colourBeforeDnD);
		System.out.println("Color after Drag and Drop : "+ colorAfterDnD);



Saurabh Dhingra

About the Author

Saurabh Dhingra

Follow Saurabh Dhingra: