Bird
0
0

Given the following code snippet, what will be the result after execution?

medium📝 Predict Output Q13 of 15
Selenium Java - Actions Class
Given the following code snippet, what will be the result after execution?
WebElement source = driver.findElement(By.id("item1"));
WebElement target = driver.findElement(By.id("box1"));
Actions actions = new Actions(driver);
actions.clickAndHold(source).moveToElement(target).release().perform();
String text = target.getText();

If the drag and drop is successful, what should text contain?
ANull value
BAn empty string
CThe text of the dragged element (item1)
DThe text of the target element before drag
Step-by-Step Solution
Solution:
  1. Step 1: Understand the drag and drop effect

    Dragging source onto target usually moves or copies the source element's content into the target area.
  2. Step 2: Check what target.getText() returns after drop

    After a successful drop, the target element's text usually remains unchanged unless the page's DOM is updated by JavaScript. The getText() method returns the visible text of the target element, which typically does not change automatically after drag and drop.
  3. Final Answer:

    The text of the target element before drag -> Option D
  4. Quick Check:

    target.getText() usually unchanged after drag and drop unless DOM updates [OK]
Quick Trick: After drop, target text usually remains the same unless DOM updates [OK]
Common Mistakes:
MISTAKES
  • Assuming target text changes automatically
  • Expecting empty or null text after drop
  • Confusing source and target texts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes