Skip to content

Commit 6d531b8

Browse files
authored
Merge pull request #4189 from seleniumbase/cdp-mode-patch-87
CDP Mode: Patch 87
2 parents eed4563 + c4664a4 commit 6d531b8

File tree

16 files changed

+188
-39
lines changed

16 files changed

+188
-39
lines changed

examples/cdp_mode/ReadMe.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,8 @@ await tab.close()
667667
await tab.scroll_down(amount=25)
668668
await tab.scroll_up(amount=25)
669669
await tab.wait_for(selector="", text="", timeout=10)
670+
await tab.set_attributes(selector, attribute, value)
671+
await tab.internalize_links()
670672
await tab.download_file(url, filename=None)
671673
await tab.save_screenshot(
672674
filename="auto", format="png", full_page=False)

examples/cdp_mode/raw_priceline.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from seleniumbase import SB
22

3-
with SB(uc=True, test=True, locale="en", incognito=True) as sb:
3+
with SB(uc=True, test=True, locale="en") as sb:
44
url = "https://www.priceline.com"
55
sb.activate_cdp_mode(url)
6-
sb.sleep(2.5)
6+
sb.sleep(1.8)
77
sb.click('input[name="endLocation"]')
88
sb.sleep(1.2)
99
location = "Portland, OR"
@@ -17,7 +17,12 @@
1717
sb.click('button[aria-label="Dismiss calendar"]')
1818
sb.sleep(0.5)
1919
sb.click('button[data-testid="HOTELS_SUBMIT_BUTTON"]')
20-
sb.sleep(5.5)
20+
sb.sleep(0.5)
21+
if sb.is_element_visible('[aria-label="Close Modal"]'):
22+
sb.click('[aria-label="Close Modal"]')
23+
sb.sleep(0.5)
24+
sb.click('button[data-testid="HOTELS_SUBMIT_BUTTON"]')
25+
sb.sleep(4.8)
2126
if len(sb.cdp.get_tabs()) > 1:
2227
sb.cdp.close_active_tab()
2328
sb.cdp.switch_to_newest_tab()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, locale="en") as sb:
4+
url = "https://www.ralphlauren.com.au/"
5+
sb.activate_cdp_mode()
6+
sb.open(url)
7+
sb.sleep(1.2)
8+
if not sb.is_element_present('[title="Locate Stores"]'):
9+
sb.cdp.evaluate("window.location.reload();")
10+
sb.sleep(1.2)
11+
category = "women"
12+
search = "Dresses"
13+
sb.click('a[data-cgid="%s"]' % category)
14+
sb.sleep(2.2)
15+
sb.click('a:contains("%s")' % search)
16+
sb.sleep(3.8)
17+
for i in range(6):
18+
sb.scroll_down(34)
19+
sb.sleep(0.25)
20+
print('*** Ralph Lauren Search for "%s":' % search)
21+
unique_item_text = []
22+
items = sb.find_elements('div.product-data')
23+
for item in items:
24+
description = item.querySelector("a.name-link")
25+
if description and description.text not in unique_item_text:
26+
unique_item_text.append(description.text)
27+
print("* " + description.text)
28+
price = item.querySelector('span[title="Price"]')
29+
if price:
30+
print(" (" + price.text.replace(" ", " ") + ")")

examples/cdp_mode/raw_totalwine.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, locale="en") as sb:
4+
url = "https://www.totalwine.com/"
5+
sb.activate_cdp_mode()
6+
sb.open(url)
7+
sb.sleep(1.8)
8+
search_box = 'input[data-at="header-search-text"]'
9+
search = "The Land by Psagot Cabernet"
10+
if not sb.is_element_present(search_box):
11+
sb.cdp.evaluate("window.location.reload();")
12+
sb.sleep(1.8)
13+
sb.click_if_visible("#onetrust-close-btn-container button")
14+
sb.sleep(0.5)
15+
sb.click_if_visible('button[aria-label="Close modal"]')
16+
sb.sleep(1.2)
17+
sb.click(search_box)
18+
sb.sleep(1.2)
19+
sb.press_keys(search_box, search)
20+
sb.sleep(0.6)
21+
sb.click('button[data-at="header-search-button"]')
22+
sb.sleep(1.8)
23+
sb.click('img[data-at="product-search-productimage"]')
24+
sb.sleep(2.2)
25+
print('*** Total Wine Search for "%s":' % search)
26+
print(sb.get_text('h1[data-at="product-name-title"]'))
27+
print(sb.get_text('span[data-at="product-mix6price-text"]'))
28+
print("Product Highlights:")
29+
print(sb.get_text('p[class*="productInformationReview"]'))
30+
print("Product Details:")
31+
print(sb.get_text('div[data-at="origin-details-table-container"]'))

examples/cdp_mode/raw_zoro.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from seleniumbase import SB
2+
3+
with SB(uc=True, test=True, locale="en") as sb:
4+
url = "https://www.zoro.com/"
5+
sb.activate_cdp_mode()
6+
sb.open(url)
7+
sb.sleep(1.2)
8+
search_box = "input#searchInput"
9+
search = "Flir Thermal Camera"
10+
required_text = "Camera"
11+
if not sb.is_element_present(search_box):
12+
sb.cdp.evaluate("window.location.reload();")
13+
sb.sleep(1.2)
14+
sb.click(search_box)
15+
sb.sleep(1.2)
16+
sb.press_keys(search_box, search)
17+
sb.sleep(0.6)
18+
sb.click('button[data-za="searchButton"]')
19+
sb.sleep(3.8)
20+
print('*** Zoro Search for "%s":' % search)
21+
print(' (Results must contain "%s".)' % required_text)
22+
unique_item_text = []
23+
items = sb.find_elements('div[data-za="search-product-card"]')
24+
for item in items:
25+
if required_text in item.text:
26+
description = item.querySelector('div[data-za="product-title"]')
27+
if description and description.text not in unique_item_text:
28+
unique_item_text.append(description.text)
29+
print("* " + description.text)
30+
price = item.querySelector("div.price-main")
31+
if price:
32+
print(" (" + price.text + ")")

examples/presenter/uc_presentation_4.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,10 +768,10 @@ def test_presentation_4(self):
768768
)
769769
self.begin_presentation(filename="uc_presentation.html")
770770

771-
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
771+
with SB(uc=True, test=True, locale="en") as sb:
772772
url = "https://www.priceline.com"
773773
sb.activate_cdp_mode(url)
774-
sb.sleep(2.5)
774+
sb.sleep(1.8)
775775
sb.click('input[name="endLocation"]')
776776
sb.sleep(1.2)
777777
location = "Portland, Oregon, US"
@@ -785,7 +785,12 @@ def test_presentation_4(self):
785785
sb.click('button[aria-label="Dismiss calendar"]')
786786
sb.sleep(0.5)
787787
sb.click('button[data-testid="HOTELS_SUBMIT_BUTTON"]')
788-
sb.sleep(5.5)
788+
sb.sleep(0.5)
789+
if sb.is_element_visible('[aria-label="Close Modal"]'):
790+
sb.click('[aria-label="Close Modal"]')
791+
sb.sleep(0.5)
792+
sb.click('button[data-testid="HOTELS_SUBMIT_BUTTON"]')
793+
sb.sleep(4.8)
789794
if len(sb.cdp.get_tabs()) > 1:
790795
sb.cdp.close_active_tab()
791796
sb.cdp.switch_to_newest_tab()

help_docs/cdp_mode_methods.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ await tab.close()
305305
await tab.scroll_down(amount=25)
306306
await tab.scroll_up(amount=25)
307307
await tab.wait_for(selector="", text="", timeout=10)
308+
await tab.set_attributes(selector, attribute, value)
309+
await tab.internalize_links()
308310
await tab.download_file(url, filename=None)
309311
await tab.save_screenshot(
310312
filename="auto", format="png", full_page=False)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ rich>=14.2.0,<15
7676
# ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.)
7777

7878
coverage>=7.10.7;python_version<"3.10"
79-
coverage>=7.13.0;python_version>="3.10"
79+
coverage>=7.13.1;python_version>="3.10"
8080
pytest-cov>=7.0.0
8181
flake8==7.3.0
8282
mccabe==0.7.0

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.45.6"
2+
__version__ = "4.45.7"

seleniumbase/core/browser_launcher.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,6 @@ def _set_chrome_options(
27382738
chrome_options.add_argument("--disable-save-password-bubble")
27392739
chrome_options.add_argument("--disable-single-click-autofill")
27402740
chrome_options.add_argument("--allow-file-access-from-files")
2741-
chrome_options.add_argument("--disable-component-update")
27422741
chrome_options.add_argument("--disable-prompt-on-repost")
27432742
chrome_options.add_argument("--dns-prefetch-disable")
27442743
chrome_options.add_argument("--disable-translate")
@@ -4793,7 +4792,6 @@ def get_local_driver(
47934792
if devtools and not headless:
47944793
edge_options.add_argument("--auto-open-devtools-for-tabs")
47954794
edge_options.add_argument("--allow-file-access-from-files")
4796-
edge_options.add_argument("--disable-component-update")
47974795
edge_options.add_argument("--allow-insecure-localhost")
47984796
edge_options.add_argument("--allow-running-insecure-content")
47994797
if user_agent:

0 commit comments

Comments
 (0)