Bird
0
0

Identify the error in the following Selenium Java code for drag and drop:

medium📝 Debug Q14 of 15
Selenium Java - Actions Class
Identify the error in the following Selenium Java code for drag and drop:
WebElement source = driver.findElement(By.id("drag"));
WebElement target = driver.findElement(By.id("drop"));
Actions actions = new Actions(driver);
actions.clickAndHold(source).moveToElement(target).perform();
AMissing <code>release()</code> before <code>perform()</code>
BIncorrect locator strategy for elements
CActions class cannot be instantiated directly
DNo need to call <code>perform()</code> after actions
Step-by-Step Solution
Solution:
  1. Step 1: Review the drag and drop sequence

    Drag and drop requires clicking and holding the source, moving to target, then releasing the mouse button before performing.
  2. Step 2: Identify missing release()

    The code misses release(), so the drop action is incomplete and will not work as expected.
  3. Final Answer:

    Missing release() before perform() -> Option A
  4. Quick Check:

    Drag and drop needs release() [OK]
Quick Trick: Always call release() before perform() in drag and drop [OK]
Common Mistakes:
  • Forgetting release() after moveToElement
  • Incorrect element locators (not in this code)
  • Not calling perform() at all

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes