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
- List of WebDriver errors
- Associated commands and types:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论