Bird
0
0

What will be printed by the following Selenium Java code?

medium📝 Predict Output Q4 of 15
Selenium Java - JavaScriptExecutor
What will be printed by the following Selenium Java code?
Object result = driver.executeAsyncScript(
  "var callback = arguments[arguments.length - 1];
  setTimeout(() => callback('finished'), 1500);"
);
System.out.println(result);
Afinished
Bnull
Cundefined
DTimeoutException
Step-by-Step Solution
Solution:
  1. Step 1: Identify callback usage

    The script uses callback to return 'finished' after 1.5 seconds.
  2. Step 2: Understand executeAsyncScript behavior

    It waits for the callback to be called and returns its argument.
  3. Final Answer:

    finished -> Option A
  4. Quick Check:

    Callback returns 'finished' after delay [OK]
Quick Trick: Callback argument is the async return value [OK]
Common Mistakes:
  • Expecting immediate return without waiting
  • Confusing callback argument position
  • Assuming exceptions without timeout

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes