File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ # Selenium examples using CDP
2+
3+ ## Prerequisites
4+
5+ ```
6+ $ pip install trio selenium
7+ ```
Original file line number Diff line number Diff line change 1+ import trio
2+ import sys
3+ import logging
4+ from selenium import webdriver
5+ from selenium .webdriver .common .by import By
6+
7+ logger = logging .getLogger ('selenium' )
8+ logger .setLevel (logging .DEBUG )
9+
10+ handler = logging .StreamHandler (sys .stderr )
11+ logger .addHandler (handler )
12+
13+ logging .getLogger ('selenium.webdriver.remote' ).setLevel (logging .WARN )
14+ logging .getLogger ('selenium.webdriver.common' ).setLevel (logging .DEBUG )
15+
16+ async def run (driver ):
17+ async with driver .bidi_connection () as session :
18+ await trio .to_thread .run_sync (lambda : driver .get ('https://blg.tch.re' ))
19+
20+ links = driver .find_elements (By .TAG_NAME , 'a' )
21+
22+ for a in links :
23+ print (a .get_attribute ("href" ))
24+
25+ options = webdriver .ChromeOptions ()
26+ options .page_load_strategy = 'normal'
27+ options .enable_bidi = True
28+ options .add_experimental_option ("debuggerAddress" , "127.0.0.1:9222" )
29+
30+ driver = webdriver .Chrome (options )
31+
32+ trio .run (run , driver )
You can’t perform that action at this time.
0 commit comments