Script timeout
The script timeout error is a WebDriver error that occurs when a script the user has provided did not complete before the session's script timeout duration expired.
The script timeout duration is a configurable capability, which means you can change how long it will take before the driver interrupts an injected script. The driver will by default wait 30 seconds before interrupting the script and returning with a script timeout error, but this can be both extended, limited, and be set to indefinite.
If the session script timeout duration is set to indefinite by using a null
value, you are at risk of putting the session into a non-recoverable state. Be aware that this should be used with caution.
Example
Consider the following asynchronous script that will resolve the promise, or invoke the callback, after 35 seconds have passed:
from selenium import webdriver
from selenium.common import exceptions
session = webdriver.Firefox()
try:
session.execute_script("""
let [resolve] = arguments;
setTimeout(resolve, 35000);
""")
except exceptions.ScriptTimeoutException as e:
print(e.message)
Output:
ScriptTimeoutException: Timed out after 35000 ms
However, it is possible to extend the session's default script timeout by using capabilities if you have a script that you expect will take longer:
from selenium import webdriver
from selenium.common import exceptions
session = webdriver.Firefox(capabilities={"alwaysMatch": {"timeouts": {"script": 150000}}})
session.execute_script("""
let [resolve] = arguments;
setTimeout(resolve, 35000);
""")
print("finished successfully")
Output:
finished successfully
See also
-
Associated commands and types: