Bird
0
0

What is wrong with this drag and drop code?

medium📝 Debug Q7 of 15
Selenium Java - Actions Class
What is wrong with this drag and drop code?
Actions actions = new Actions(driver);
WebElement source = driver.findElement(By.id("source"));
WebElement target = driver.findElement(By.id("target"));
actions.clickAndHold(source).moveToElement(target).release();
AclickAndHold cannot be used for drag and drop
BmoveToElement requires coordinates as parameters
CMissing perform() call to execute the action chain
Drelease() should be called before moveToElement
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the action chain

    The chain builds the drag and drop steps but does not execute without perform().
  2. Step 2: Identify missing method

    perform() is missing, so the actions won't run.
  3. Final Answer:

    Missing perform() call to execute the action chain -> Option C
  4. Quick Check:

    Always call perform() after building Actions [OK]
Quick Trick: Call perform() to run Actions chain [OK]
Common Mistakes:
  • Omitting perform() after action sequences
  • Misunderstanding moveToElement parameters
  • Calling release() before moveToElement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes