大网数据广告活动
Web 标准与前端开发

`script timeout` error code

· 52CE 我爱测

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 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

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。