Bird
0
0

What is wrong with this async script?

medium📝 Debug Q7 of 15
Selenium Java - JavaScriptExecutor
What is wrong with this async script?
driver.executeAsyncScript(
  "var callback = arguments[0];
  setTimeout(function() { callback('done'); }, 500);"
);
ANo error, script is correct
BsetTimeout duration too short
CCallback argument index is incorrect
DCallback called with wrong data type
Step-by-Step Solution
Solution:
  1. Step 1: Check callback argument index

    Callback is always the last argument, so arguments[0] is incorrect.
  2. Step 2: Effect of wrong index

    Using arguments[0] may refer to a different argument, causing failure to signal completion.
  3. Final Answer:

    Callback argument index is incorrect -> Option C
  4. Quick Check:

    Callback is last argument, not first [OK]
Quick Trick: Callback is last argument, not first [OK]
Common Mistakes:
  • Using arguments[0] instead of last argument
  • Assuming any argument can be callback
  • Ignoring callback position rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes