Bird
0
0

Identify the error in this Selenium Java async script usage:

medium📝 Debug Q14 of 15
Selenium Java - JavaScriptExecutor
Identify the error in this Selenium Java async script usage:
driver.executeAsyncScript("setTimeout(() => { return 'done'; }, 1000);");
AMissing callback argument and not calling it to signal completion.
BUsing arrow function inside executeAsyncScript is not allowed.
CTimeout value should be zero for async scripts.
DexecuteAsyncScript cannot run setTimeout functions.
Step-by-Step Solution
Solution:
  1. Step 1: Check async script requirements

    Async scripts must accept a callback argument and call it to signal completion.
  2. Step 2: Analyze the given code

    The code uses setTimeout but does not accept or call any callback, so Selenium never knows when to continue.
  3. Final Answer:

    Missing callback argument and not calling it to signal completion. -> Option A
  4. Quick Check:

    Callback must be called = D [OK]
Quick Trick: Always pass and call callback in async scripts [OK]
Common Mistakes:
  • Forgetting to pass callback as argument
  • Returning value instead of calling callback
  • Thinking arrow functions are disallowed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes