Bird
0
0

What will be the result of the following code snippet?

medium📝 Predict Output Q4 of 15
Selenium Java - Actions Class
What will be the result of the following code snippet?
Actions actions = new Actions(driver);
WebElement source = driver.findElement(By.id("drag"));
WebElement target = driver.findElement(By.id("drop"));
actions.dragAndDrop(source, target).perform();
String text = target.getText();
System.out.println(text);

Assuming the drag and drop is successful and the target element's text changes to "Dropped!" after drop, what is printed?
A"Dropped!"
B"drag"
C"drop"
DAn exception is thrown
Step-by-Step Solution
Solution:
  1. Step 1: Understand dragAndDrop effect

    The dragAndDrop moves the source element onto the target, triggering a text change to "Dropped!".
  2. Step 2: Check what is printed

    After performing, target.getText() returns the updated text "Dropped!", which is printed.
  3. Final Answer:

    "Dropped!" -> Option A
  4. Quick Check:

    dragAndDrop success = prints updated target text [OK]
Quick Trick: After dragAndDrop, target text updates if UI changes [OK]
Common Mistakes:
MISTAKES
  • Expecting source text instead of target text
  • Assuming no text change after drag and drop
  • Ignoring need to call perform()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes