Bird
0
0

What will be the output of the following Selenium Java code snippet?

medium📝 Predict Output Q13 of 15
Selenium Java - JavaScriptExecutor
What will be the output of the following Selenium Java code snippet?
Object result = driver.executeAsyncScript(
  "var callback = arguments[0]; setTimeout(() => callback('done'), 500);");
System.out.println(result);
ATimeoutException
Bnull
Cdone
Dundefined
Step-by-Step Solution
Solution:
  1. Step 1: Understand the async script behavior

    The script waits 500ms then calls callback with 'done'. Selenium waits for this callback and returns its value.
  2. Step 2: Check what is printed

    The returned value from executeAsyncScript is 'done', so System.out.println prints 'done'.
  3. Final Answer:

    done -> Option C
  4. Quick Check:

    Callback returns 'done' = C [OK]
Quick Trick: Callback value is returned and printed [OK]
Common Mistakes:
  • Expecting null before callback runs
  • Confusing async script with synchronous
  • Assuming timeout error without delay

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes