Skip to content

Commit bd121c4

Browse files
authored
Using async/await in JavaScript in Selenium
1 parent 82cab51 commit bd121c4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Using async/await in JavaScript in Selenium
2+
3+
Thanks [Stuart Langridge](https://twitter.com/sil/status/1312137808111304704) for showing me how to do this:
4+
5+
```python
6+
from selenium import webdriver
7+
8+
chromedriver_path = "/Users/simon/bin/chromedriver"
9+
driver = webdriver.Chrome(executable_path=chromedriver_path)
10+
11+
script = """
12+
done = arguments[arguments.length-1];
13+
a1 = async () => {
14+
return 42
15+
};
16+
a2 = async() => {
17+
return await a1()+1
18+
};
19+
a2().then(done);
20+
"""
21+
output = driver.execute_async_script(script)
22+
# output is now the Python integer 43
23+
```

0 commit comments

Comments
 (0)