Skip to content

Commit 5aaeb39

Browse files
authored
Merge pull request #4135 from seleniumbase/cdp-mode-patch-80
CDP Mode: Patch 80
2 parents d350947 + 1f1bf5d commit 5aaeb39

27 files changed

+268
-331
lines changed

examples/cdp_mode/ReadMe.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ from seleniumbase import SB
140140
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
141141
url = "https://www.pokemon.com/us"
142142
sb.activate_cdp_mode(url)
143-
sb.sleep(3.5)
143+
sb.sleep(1.5)
144144
sb.click_if_visible("button#onetrust-accept-btn-handler")
145145
sb.sleep(1.2)
146146
sb.click("a span.icon_pokeball")
@@ -193,7 +193,7 @@ from seleniumbase import SB
193193
with SB(uc=True, test=True, locale="en") as sb:
194194
url = "https://www.hyatt.com/"
195195
sb.activate_cdp_mode(url)
196-
sb.sleep(3.8)
196+
sb.sleep(3.2)
197197
sb.click_if_visible('button[aria-label="Close"]')
198198
sb.sleep(0.1)
199199
sb.click_if_visible("#onetrust-reject-all-handler")
@@ -282,7 +282,11 @@ from seleniumbase import SB
282282
with SB(uc=True, test=True, ad_block=True) as sb:
283283
url = "https://www.walmart.com/"
284284
sb.activate_cdp_mode(url)
285-
sb.sleep(2.8)
285+
sb.sleep(1.8)
286+
continue_button = 'button:contains("Continue shopping")'
287+
if sb.is_element_visible(continue_button):
288+
sb.cdp.gui_click_element(continue_button)
289+
sb.sleep(0.6)
286290
sb.click('input[aria-label="Search"]')
287291
sb.sleep(1.2)
288292
search = "Settlers of Catan Board Game"

examples/cdp_mode/raw_cdp_hyatt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
url = "https://www.hyatt.com/"
44
sb = sb_cdp.Chrome(url, locale="en", guest=True)
5-
sb.sleep(4.2)
5+
sb.sleep(3.6)
66
sb.click_if_visible('button[aria-label="Close"]')
77
sb.sleep(0.1)
88
sb.click_if_visible("#onetrust-reject-all-handler")

examples/cdp_mode/raw_hyatt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
with SB(uc=True, test=True, locale="en") as sb:
44
url = "https://www.hyatt.com/"
55
sb.activate_cdp_mode(url)
6-
sb.sleep(3.8)
6+
sb.sleep(3.2)
77
sb.click_if_visible('button[aria-label="Close"]')
88
sb.sleep(0.1)
99
sb.click_if_visible("#onetrust-reject-all-handler")

examples/cdp_mode/raw_pokemon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
with SB(uc=True, test=True, locale="en", guest=True) as sb:
44
url = "https://www.pokemon.com/us"
55
sb.activate_cdp_mode(url)
6-
sb.sleep(3.5)
6+
sb.sleep(1.5)
77
sb.click_if_visible("button#onetrust-accept-btn-handler")
88
sb.sleep(1.2)
99
sb.click("a span.icon_pokeball")

examples/cdp_mode/raw_walmart.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
with SB(uc=True, test=True, ad_block=True) as sb:
44
url = "https://www.walmart.com/"
55
sb.activate_cdp_mode(url)
6-
sb.sleep(2.8)
6+
sb.sleep(1.8)
7+
continue_button = 'button:contains("Continue shopping")'
8+
if sb.is_element_visible(continue_button):
9+
sb.cdp.gui_click_element(continue_button)
10+
sb.sleep(0.6)
711
sb.click('input[aria-label="Search"]')
812
sb.sleep(1.2)
913
search = "Settlers of Catan Board Game"

examples/cdp_mode/raw_xhr_async.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ async def crawl():
6464

6565
# Change url to something that makes ajax requests
6666
tab = await driver.get("https://learn.microsoft.com/en-us/")
67-
time.sleep(2)
68-
for i in range(20):
69-
await tab.scroll_down(4)
67+
time.sleep(1.5)
68+
for i in range(18):
69+
await tab.scroll_down(3)
7070
time.sleep(0.02)
7171

7272
xhr_responses = await receiveXHR(tab, xhr_requests)

examples/cdp_mode/raw_xhr_sb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ async def receiveXHR(page, requests):
6363

6464
# Change url to something that makes ajax requests
6565
sb.cdp.open("https://learn.microsoft.com/en-us/")
66-
time.sleep(2)
67-
for i in range(10):
68-
sb.cdp.scroll_down(8)
66+
time.sleep(1)
67+
for i in range(9):
68+
sb.cdp.scroll_down(6)
6969

7070
loop = sb.cdp.get_event_loop()
7171
xhr_responses = loop.run_until_complete(receiveXHR(tab, xhr_requests))

examples/presenter/uc_presentation_4.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def test_presentation_4(self):
463463
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
464464
url = "https://www.pokemon.com/us"
465465
sb.activate_cdp_mode(url)
466-
sb.sleep(3.5)
466+
sb.sleep(1.5)
467467
sb.click_if_visible("button#onetrust-accept-btn-handler")
468468
sb.sleep(1.2)
469469
sb.click("a span.icon_pokeball")
@@ -515,7 +515,11 @@ def test_presentation_4(self):
515515
with SB(uc=True, test=True, ad_block=True) as sb:
516516
url = "https://www.walmart.com/"
517517
sb.activate_cdp_mode(url)
518-
sb.sleep(2.8)
518+
sb.sleep(1.8)
519+
continue_button = 'button:contains("Continue shopping")'
520+
if sb.is_element_visible(continue_button):
521+
sb.cdp.gui_click_element(continue_button)
522+
sb.sleep(0.6)
519523
sb.click('input[aria-label="Search"]')
520524
sb.sleep(1.2)
521525
search = "Settlers of Catan Board Game"
@@ -679,7 +683,7 @@ def test_presentation_4(self):
679683
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
680684
url = "https://www.hyatt.com/"
681685
sb.activate_cdp_mode(url)
682-
sb.sleep(3.5)
686+
sb.sleep(3.2)
683687
sb.click_if_visible('button[aria-label="Close"]')
684688
sb.sleep(0.1)
685689
sb.click_if_visible("#onetrust-reject-all-handler")

examples/raw_multi_sb.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sys
2+
import threading
3+
from concurrent.futures import ThreadPoolExecutor
4+
from random import randint, seed
5+
from seleniumbase import SB
6+
sys.argv.append("-n") # Tell SeleniumBase to do thread-locking as needed
7+
8+
9+
def launch_driver(url):
10+
seed(len(threading.enumerate())) # Random seed for browser placement
11+
with SB() as sb:
12+
sb.set_window_rect(randint(4, 720), randint(8, 410), 700, 500)
13+
sb.open(url=url)
14+
if sb.is_element_visible("h1"):
15+
sb.highlight("h1", loops=9)
16+
else:
17+
sb.sleep(2.2)
18+
19+
20+
if __name__ == "__main__":
21+
urls = ['https://seleniumbase.io/demo_page' for i in range(4)]
22+
with ThreadPoolExecutor(max_workers=len(urls)) as executor:
23+
for url in urls:
24+
executor.submit(launch_driver, url)

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.44.17"
2+
__version__ = "4.44.18"

0 commit comments

Comments
 (0)