Web Driver executeJavascript exceeds timeout limit without returning result or throwing error

My script calls executeJavascript to find web element. If there is web element, it returns the element. Other than that, it should return null. The script should return result in under 1 second, which I verified through logging.

The issue is at a certain point in the script, executeJavascript seems to be on hold indefinitely. It didn’t return any result nor did it throw StepFailedException error. For the script timeout set to 5 seconds, the fact that the function took indefinitely to run is beyond my understanding.

The only way I could get the script to continue running was to click on the page. That seemingly triggered something under the hood that “activated” the browser, web driver, engine, etc.. I tried to simulate a user click with executeCdpCommand and Java Robot and they failed to simulate the real click.

If executeJavascript throws error, I want it to throw within the predetermined script timeout (5 seconds).

Possibly the javascript code you gave to WebUI.executeJavascript(String script, List args) got hold indefinitely. So you should review your script code first before blaming executeJavascript.