Bird
0
0

Identify the error in this drag and drop code snippet:

medium📝 Debug Q6 of 15
Selenium Java - Actions Class
Identify the error in this drag and drop code snippet:
Actions actions = new Actions(driver);
WebElement source = driver.findElement(By.id("source"));
WebElement target = driver.findElement(By.id("target"));
actions.dragAndDrop(source, target);
AdragAndDrop method requires three parameters
BMissing perform() call to execute the action
CActions class cannot be instantiated this way
DIncorrect locator strategy used
Step-by-Step Solution
Solution:
  1. Step 1: Review dragAndDrop usage

    The dragAndDrop method returns an Actions object but does not execute until perform() is called.
  2. Step 2: Check the code snippet

    perform() is missing, so the drag and drop will not happen.
  3. Final Answer:

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

    Always call perform() after Actions chain [OK]
Quick Trick: Always end Actions with perform() to run [OK]
Common Mistakes:
  • Forgetting perform() after dragAndDrop
  • Assuming dragAndDrop executes immediately
  • Incorrect locator usage (not in this snippet)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes