Bird
0
0

You want to drag an element from one location to another offset by (100, 50) pixels. Which code correctly performs this drag using Actions in Selenium Java?

hard📝 Application Q9 of 15
Selenium Java - Actions Class
You want to drag an element from one location to another offset by (100, 50) pixels. Which code correctly performs this drag using Actions in Selenium Java?
Anew Actions(driver).dragAndDropBy(element, 100, 50).perform();
Bnew Actions(driver).clickAndHold(element).moveByOffset(100, 50).perform();
Cnew Actions(driver).moveToElement(element).dragAndDropBy(100, 50).perform();
Dnew Actions(driver).click(element).moveByOffset(100, 50).release().perform();
Step-by-Step Solution
Solution:
  1. Step 1: Understand dragAndDropBy

    dragAndDropBy(element, x, y) drags element by given offset.
  2. Step 2: Correct usage

    Calling dragAndDropBy with perform() executes the drag correctly.
  3. Step 3: Compare alternatives

    new Actions(driver).clickAndHold(element).moveByOffset(100, 50).perform(); is incorrect (missing release()). new Actions(driver).dragAndDropBy(element, 100, 50).perform(); is simpler and correct. new Actions(driver).moveToElement(element).dragAndDropBy(100, 50).perform(); is invalid syntax. new Actions(driver).click(element).moveByOffset(100, 50).release().perform(); misses clickAndHold.
  4. Final Answer:

    new Actions(driver).dragAndDropBy(element, 100, 50).perform(); -> Option A
  5. Quick Check:

    dragAndDropBy + perform() = drag by offset [OK]
Quick Trick: Use dragAndDropBy for simple drag by offset [OK]
Common Mistakes:
MISTAKES
  • Missing release() in manual drag
  • Incorrect chaining of dragAndDropBy
  • Using click() instead of clickAndHold

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes