-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
66 lines (48 loc) · 2.22 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
title: Script timeout
slug: Web/WebDriver/Errors/ScriptTimeout
page-type: webdriver-error
---
{{QuickLinksWithSubpages("/en-US/docs/Web/WebDriver/Errors")}}
The **script timeout** error is a [WebDriver error](/en-US/docs/Web/WebDriver/Errors) 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:
```python
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:
```plain
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:
```python
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:
```plain
finished successfully
```
## See also
- [List of WebDriver errors](/en-US/docs/Web/WebDriver/Errors)
- Associated commands and types:
- [JavaScript error](/en-US/docs/Web/WebDriver/Errors/JavaScriptError)
- [Execute Script](/en-US/docs/Web/WebDriver/Commands/ExecuteScript)
- [Execute Async Script](/en-US/docs/Web/WebDriver/Commands/ExecuteAsyncScript)