-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathraw_multi_async.py
More file actions
32 lines (26 loc) · 1008 Bytes
/
raw_multi_async.py
File metadata and controls
32 lines (26 loc) · 1008 Bytes
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
# Testing multiple CDP drivers using the async API
import asyncio
from concurrent.futures import ThreadPoolExecutor
from random import randint
from seleniumbase import cdp_driver
from seleniumbase import decorators
async def main(url):
driver = await cdp_driver.start_async()
page = await driver.get(url)
await page.set_window_rect(randint(4, 600), randint(8, 410), 860, 500)
await page.sleep(0.5)
field = await page.select("input")
await field.send_keys_async("Text")
button = await page.select("button")
await button.click_async()
await page.sleep(2)
driver.stop()
def set_up_loop(url):
loop = asyncio.new_event_loop()
loop.run_until_complete(main(url))
if __name__ == "__main__":
urls = ["https://seleniumbase.io/demo_page" for i in range(5)]
with decorators.print_runtime("raw_multi_async.py"):
with ThreadPoolExecutor(max_workers=len(urls)) as executor:
for url in urls:
executor.submit(set_up_loop, url)