
Selenium Assignment – 4 (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.
Scenario:
- Open a browser of your choice for example – Chrome Browser.
- Navigate to http://jqueryui.com/droppable/ webpage.

- 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.

- 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.)
package com.test.traveltest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class Assignment4 {
WebDriver driver;
String Url = "https://jqueryui.com/droppable/";
WebElement webFrame;
@BeforeClass
public void invokeBrowser(){
System.setProperty("webdriver.gecko.driver",
"D:\\Selenium\\geckodriver-v0.31.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
driver.get(Url);
}
@Test
public void Test1() {
webFrame = driver.findElement(By.className("demo-frame"));
driver.switchTo().frame(webFrame);
WebElement source = driver.findElement(By.id("draggable"));
WebElement target = driver.findElement(By.id("droppable"));
Actions action = new Actions(driver);
String colourBeforeDnD = target.getCssValue("color");
//action.dragAndDrop(source, target).build().perform();
action.moveToElement(source).clickAndHold().moveToElement(target).release().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);
}
@AfterTest
public void testComplete() {
driver.close();
}
}