Script timeout - WebDriver 编辑

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;
        window.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(capabilites={"alwaysMatch": {"timeouts": {"script": 150000}}})
session.execute_script("""
    let [resolve] = arguments;
    window.setTimeout(resolve, 35000);
    """)
print("finished successfully")

Output:

finished successfully

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:144 次

字数:2770

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文