Bird
0
0

Given the following code:

medium📝 Predict Output Q5 of 15
Selenium Java - Actions Class
Given the following code:
Actions actions = new Actions(driver);
WebElement handle = driver.findElement(By.id("handle"));
actions.clickAndHold(handle).moveByOffset(100, 0).release().perform();

What is the expected outcome?
AThe element is moved vertically by 100 pixels.
BThe element is clicked but not moved.
CThe element with id 'handle' is dragged 100 pixels to the right and then released.
DAn exception is thrown because moveByOffset() cannot be chained after clickAndHold().
Step-by-Step Solution
Solution:
  1. Step 1: clickAndHold(handle)

    Presses and holds the mouse button on the element.
  2. Step 2: moveByOffset(100, 0)

    Moves the mouse cursor 100 pixels horizontally to the right while holding the element.
  3. Step 3: release() and perform()

    Releases the mouse button and executes the action chain.
  4. Final Answer:

    The element with id 'handle' is dragged 100 pixels to the right and then released. -> Option C
  5. Quick Check:

    clickAndHold + moveByOffset + release = drag and drop [OK]
Quick Trick: moveByOffset after clickAndHold drags element [OK]
Common Mistakes:
  • Assuming moveByOffset moves element vertically by default
  • Believing moveByOffset cannot be chained
  • Forgetting to call perform()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes