Drag and Drop

Drag the source card into the drop zone using Selenium Actions class.

Drag source
Drop target
How to test
// Java
WebElement source = driver.findElement(By.id("drag_source"));
WebElement target = driver.findElement(By.id("drop_target"));
new Actions(driver).dragAndDrop(source, target).perform();

# Python
source = driver.find_element(By.ID, "drag_source")
target = driver.find_element(By.ID, "drop_target")
ActionChains(driver).drag_and_drop(source, target).perform()

// Java - Full Test
driver.findElement(By.id("drag_drop_reset")).click();
WebElement source = driver.findElement(By.id("drag_source"));
WebElement target = driver.findElement(By.id("drop_target"));
Actions actions = new Actions(driver);
actions.dragAndDrop(source, target).perform();
WebElement result = driver.findElement(By.id("drag_drop_success"));
assert result.getText().contains("Drag and drop completed");
assert target.getAttribute("data-dropped").equals("true");

# Python - Full Test
driver.find_element(By.ID, "drag_drop_reset").click()
source = driver.find_element(By.ID, "drag_source")
target = driver.find_element(By.ID, "drop_target")
ActionChains(driver).drag_and_drop(source, target).perform()
result = driver.find_element(By.ID, "drag_drop_success")
assert "Drag and drop completed" in result.text
assert target.get_attribute("data-dropped") == "true"

// Java - Alternative Solution
new Actions(driver)
    .clickAndHold(driver.findElement(By.id("drag_source")))
    .moveToElement(driver.findElement(By.id("drop_target")))
    .release()
    .perform();

# Python - Alternative Solution
ActionChains(driver) \
    .click_and_hold(driver.find_element(By.ID, "drag_source")) \
    .move_to_element(driver.find_element(By.ID, "drop_target")) \
    .release() \
    .perform()


Tester Task
  1. Locate the source using id drag_source.
  2. Locate the target using id drop_target.
  3. Use Selenium Actions to drag the source to the target.
  4. Verify drag_drop_success is displayed.
  5. Verify drop_target has data-dropped="true".