File tree Expand file tree Collapse file tree 13 files changed +255
-0
lines changed
examples/cdp_mode/playwright Expand file tree Collapse file tree 13 files changed +255
-0
lines changed Original file line number Diff line number Diff line change 1+ import asyncio
2+ from playwright .async_api import async_playwright
3+ from seleniumbase import cdp_driver
4+
5+
6+ async def main ():
7+ driver = await cdp_driver .start_async ()
8+ endpoint_url = driver .get_endpoint_url ()
9+
10+ async with async_playwright () as p :
11+ browser = await p .chromium .connect_over_cdp (endpoint_url )
12+ context = browser .contexts [0 ]
13+ page = context .pages [0 ]
14+ await page .goto ("https://seleniumbase.io/simple/login" )
15+ await page .fill ("#username" , "demo_user" )
16+ await page .fill ("#password" , "secret_pass" )
17+ await page .click ("#log-in" )
18+ await page .wait_for_selector ("h1" )
19+ await driver .sleep (1 )
20+
21+
22+ if __name__ == "__main__" :
23+ loop = asyncio .new_event_loop ()
24+ loop .run_until_complete (main ())
Original file line number Diff line number Diff line change 1+ from playwright .sync_api import sync_playwright
2+ from seleniumbase import SB
3+
4+ with SB (uc = True ) as sb :
5+ sb .activate_cdp_mode ()
6+ endpoint_url = sb .cdp .get_endpoint_url ()
7+
8+ with sync_playwright () as p :
9+ browser = p .chromium .connect_over_cdp (endpoint_url )
10+ context = browser .contexts [0 ]
11+ page = context .pages [0 ]
12+ page .goto ("https://seleniumbase.io/simple/login" )
13+ page .fill ("#username" , "demo_user" )
14+ page .fill ("#password" , "secret_pass" )
15+ page .click ("#log-in" )
16+ page .wait_for_selector ("h1" )
17+ sb .sleep (1 )
Original file line number Diff line number Diff line change 1+ from playwright .sync_api import sync_playwright
2+ from seleniumbase import sb_cdp
3+
4+ sb = sb_cdp .Chrome ()
5+ endpoint_url = sb .get_endpoint_url ()
6+
7+ with sync_playwright () as p :
8+ browser = p .chromium .connect_over_cdp (endpoint_url )
9+ context = browser .contexts [0 ]
10+ page = context .pages [0 ]
11+ page .goto ("https://seleniumbase.io/simple/login" )
12+ page .fill ("#username" , "demo_user" )
13+ page .fill ("#password" , "secret_pass" )
14+ page .click ("#log-in" )
15+ page .wait_for_selector ("h1" )
16+ sb .sleep (1 )
Original file line number Diff line number Diff line change 1+ import asyncio
2+ from playwright .async_api import async_playwright
3+ from seleniumbase import cdp_driver
4+
5+
6+ async def main ():
7+ driver = await cdp_driver .start_async (locale = "en" )
8+ endpoint_url = driver .get_endpoint_url ()
9+
10+ async with async_playwright () as p :
11+ browser = await p .chromium .connect_over_cdp (endpoint_url )
12+ context = browser .contexts [0 ]
13+ page = context .pages [0 ]
14+ await page .goto ("https://www.bing.com/turing/captcha/challenge" )
15+ await driver .sleep (3 )
16+ await driver .solve_captcha ()
17+ await driver .sleep (3 )
18+
19+
20+ if __name__ == "__main__" :
21+ loop = asyncio .new_event_loop ()
22+ loop .run_until_complete (main ())
Original file line number Diff line number Diff line change 1+ from playwright .sync_api import sync_playwright
2+ from seleniumbase import SB
3+
4+ with SB (uc = True , locale = "en" ) as sb :
5+ sb .activate_cdp_mode ()
6+ endpoint_url = sb .cdp .get_endpoint_url ()
7+
8+ with sync_playwright () as p :
9+ browser = p .chromium .connect_over_cdp (endpoint_url )
10+ context = browser .contexts [0 ]
11+ page = context .pages [0 ]
12+ page .goto ("https://www.bing.com/turing/captcha/challenge" )
13+ sb .sleep (3 )
14+ sb .solve_captcha ()
15+ sb .sleep (3 )
Original file line number Diff line number Diff line change 1+ from playwright .sync_api import sync_playwright
2+ from seleniumbase import sb_cdp
3+
4+ sb = sb_cdp .Chrome (locale = "en" )
5+ endpoint_url = sb .get_endpoint_url ()
6+
7+ with sync_playwright () as p :
8+ browser = p .chromium .connect_over_cdp (endpoint_url )
9+ context = browser .contexts [0 ]
10+ page = context .pages [0 ]
11+ page .goto ("https://www.bing.com/turing/captcha/challenge" )
12+ sb .sleep (3 )
13+ sb .solve_captcha ()
14+ sb .sleep (3 )
Original file line number Diff line number Diff line change 1+ import asyncio
2+ from playwright .async_api import async_playwright
3+ from seleniumbase import cdp_driver
4+
5+
6+ async def main ():
7+ driver = await cdp_driver .start_async ()
8+ endpoint_url = driver .get_endpoint_url ()
9+
10+ async with async_playwright () as p :
11+ browser = await p .chromium .connect_over_cdp (endpoint_url )
12+ context = browser .contexts [0 ]
13+ page = context .pages [0 ]
14+ await page .goto ("https://copilot.microsoft.com" )
15+ await page .wait_for_selector ("textarea#userInput" )
16+ await driver .sleep (1 )
17+ query = "Playwright Python connect_over_cdp() sync example"
18+ await page .fill ("textarea#userInput" , query )
19+ await page .click ('button[data-testid="submit-button"]' )
20+ await driver .sleep (3 )
21+ await driver .solve_captcha ()
22+ await page .wait_for_selector ('button[data-testid*="-thumbs-up"]' )
23+ await driver .sleep (4 )
24+ await page .click ('button[data-testid*="scroll-to-bottom"]' )
25+ await driver .sleep (3 )
26+ chat_results = '[data-testid="highlighted-chats"]'
27+ result = await page .locator (chat_results ).inner_text ()
28+ print (result .replace ("\n \n " , " \n " ))
29+
30+
31+ if __name__ == "__main__" :
32+ loop = asyncio .new_event_loop ()
33+ loop .run_until_complete (main ())
Original file line number Diff line number Diff line change 1+ from playwright .sync_api import sync_playwright
2+ from seleniumbase import SB
3+
4+ with SB (uc = True ) as sb :
5+ sb .activate_cdp_mode ()
6+ endpoint_url = sb .cdp .get_endpoint_url ()
7+
8+ with sync_playwright () as p :
9+ browser = p .chromium .connect_over_cdp (endpoint_url )
10+ context = browser .contexts [0 ]
11+ page = context .pages [0 ]
12+ page .goto ("https://copilot.microsoft.com" )
13+ page .wait_for_selector ("textarea#userInput" )
14+ sb .sleep (1 )
15+ query = "Playwright Python connect_over_cdp() sync example"
16+ page .fill ("textarea#userInput" , query )
17+ page .click ('button[data-testid="submit-button"]' )
18+ sb .sleep (3 )
19+ sb .solve_captcha ()
20+ page .wait_for_selector ('button[data-testid*="-thumbs-up"]' )
21+ sb .sleep (4 )
22+ page .click ('button[data-testid*="scroll-to-bottom"]' )
23+ sb .sleep (3 )
24+ chat_results = '[data-testid="highlighted-chats"]'
25+ result = page .locator (chat_results ).inner_text ()
26+ print (result .replace ("\n \n " , " \n " ))
Original file line number Diff line number Diff line change 1+ from playwright .sync_api import sync_playwright
2+ from seleniumbase import sb_cdp
3+
4+ sb = sb_cdp .Chrome ()
5+ endpoint_url = sb .get_endpoint_url ()
6+
7+ with sync_playwright () as p :
8+ browser = p .chromium .connect_over_cdp (endpoint_url )
9+ context = browser .contexts [0 ]
10+ page = context .pages [0 ]
11+ page .goto ("https://copilot.microsoft.com" )
12+ page .wait_for_selector ("textarea#userInput" )
13+ sb .sleep (1 )
14+ query = "Playwright Python connect_over_cdp() sync example"
15+ page .fill ("textarea#userInput" , query )
16+ page .click ('button[data-testid="submit-button"]' )
17+ sb .sleep (3 )
18+ sb .solve_captcha ()
19+ page .wait_for_selector ('button[data-testid*="-thumbs-up"]' )
20+ sb .sleep (4 )
21+ page .click ('button[data-testid*="scroll-to-bottom"]' )
22+ sb .sleep (3 )
23+ chat_results = '[data-testid="highlighted-chats"]'
24+ result = page .locator (chat_results ).inner_text ()
25+ print (result .replace ("\n \n " , " \n " ))
You can’t perform that action at this time.
0 commit comments