Bird
0
0

What is the issue with this Selenium Java async script?

medium📝 Debug Q6 of 15
Selenium Java - JavaScriptExecutor
What is the issue with this Selenium Java async script?
driver.executeAsyncScript(
  "var callback = arguments[0];
  setTimeout(function() { console.log('done'); }, 1000);"
);
AThe script uses the wrong argument index for the callback.
BThe callback is called too early before the timeout.
CThe callback function is never called, so the script never completes.
DThe <code>console.log</code> statement causes an error in Selenium.
Step-by-Step Solution
Solution:
  1. Step 1: Check callback invocation

    The script logs 'done' but never calls callback.
  2. Step 2: Understand async script completion

    Without calling callback, Selenium waits indefinitely.
  3. Final Answer:

    The callback function is never called, so the script never completes. -> Option C
  4. Quick Check:

    Callback must be called to finish async script [OK]
Quick Trick: Always call callback to finish async script [OK]
Common Mistakes:
  • Forgetting to call the callback function
  • Assuming console.log ends the script
  • Using wrong argument index for callback

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes