Skip to content

Commit a75eadb

Browse files
authored
Merge pull request #4277 from seleniumbase/cdp-mode-patch-97
CDP Mode: Patch 97
2 parents f94f4a7 + c0fad26 commit a75eadb

File tree

12 files changed

+163
-92
lines changed

12 files changed

+163
-92
lines changed

examples/cdp_mode/raw_cf.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
"""Using CDP Mode with PyAutoGUI to bypass CAPTCHAs."""
1+
"""Using CDP Mode to bypass CAPTCHAs in different ways."""
22
from seleniumbase import SB
33

44
with SB(uc=True, test=True, guest=True) as sb:
55
url = "https://www.cloudflare.com/login"
66
sb.activate_cdp_mode(url)
77
sb.sleep(3)
8-
sb.uc_gui_handle_captcha() # PyAutoGUI press Tab and Spacebar
8+
sb.uc_gui_handle_captcha() # PyAutoGUI Tabs + Spacebar
99
sb.sleep(3)
1010

1111
with SB(uc=True, test=True, guest=True) as sb:
1212
url = "https://www.cloudflare.com/login"
1313
sb.activate_cdp_mode(url)
1414
sb.sleep(4)
15-
sb.uc_gui_click_captcha() # PyAutoGUI click. (Linux needs it)
15+
sb.uc_gui_click_captcha() # PyAutoGUI mouse click
16+
sb.sleep(3)
17+
18+
with SB(uc=True, test=True, guest=True) as sb:
19+
url = "https://www.cloudflare.com/login"
20+
sb.activate_cdp_mode(url)
21+
sb.sleep(4)
22+
sb.solve_captcha() # CDP Input.dispatchMouseEvent
1623
sb.sleep(3)

examples/cdp_mode/raw_nevada_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Business Entity Search / Bypasses hCaptcha."""
22
from seleniumbase import SB
33

4-
with SB(uc=True, test=True, guest=True) as sb:
4+
with SB(uc=True, test=True) as sb:
55
url = "https://www.nvsilverflume.gov/home"
66
sb.activate_cdp_mode(url)
77
sb.sleep(3)

examples/cdp_mode/raw_pixelscan.py

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

3-
with SB(uc=True, test=True, incognito=True) as sb:
3+
with SB(uc=True, test=True, incognito=True, ad_block=True) as sb:
44
url = "https://pixelscan.net/fingerprint-check"
55
sb.activate_cdp_mode(url)
6-
sb.remove_element("#headerBanner")
76
sb.wait_for_element("pxlscn-dynamic-ad")
87
sb.sleep(0.5)
98
sb.remove_elements("pxlscn-dynamic-ad")
109
sb.sleep(2)
1110
sb.assert_text("No masking detected", "pxlscn-fingerprint-masking")
1211
sb.assert_text("No automated behavior", "pxlscn-bot-detection")
13-
sb.cdp.highlight('span:contains("is consistent")')
14-
sb.sleep(1)
1512
sb.cdp.highlight("pxlscn-fingerprint-masking p")
1613
sb.sleep(1)
1714
sb.cdp.highlight("pxlscn-bot-detection p")
15+
sb.sleep(1)
16+
sb.cdp.highlight('span.status-success')
1817
sb.sleep(2)

examples/cdp_mode/raw_priceline.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1+
"""Priceline does a lot of A/B testing. Selectors change frequently."""
12
from seleniumbase import SB
23

3-
with SB(uc=True, test=True, locale="en", guest=True, ad_block=True) as sb:
4+
with SB(uc=True, test=True, locale="en", guest=True, pls="none") as sb:
45
url = "https://www.priceline.com"
56
sb.activate_cdp_mode(url)
6-
sb.sleep(1.8)
7-
sb.click('input[name="endLocation"]')
7+
sb.sleep(2.6)
8+
input_selector = '[name="endLocation"]'
9+
if not sb.is_element_present(input_selector):
10+
input_selector = "div.location-input input"
11+
sb.click(input_selector)
812
sb.sleep(1.2)
913
location = "Portland, OR"
1014
selection = "Oregon, United States" # (Dropdown option)
11-
sb.press_keys('input[name="endLocation"]', location)
12-
sb.sleep(0.5)
13-
sb.click_if_visible('input[name="endLocation"]')
14-
sb.sleep(0.5)
15+
sb.press_keys(input_selector, location)
16+
sb.sleep(0.6)
1517
sb.click(selection)
18+
sb.sleep(0.4)
1619
sb.scroll_down(25)
17-
sb.click_if_visible('button[aria-label="Dismiss calendar"]')
18-
sb.click_if_visible("div.sidebar-iframe-close")
19-
sb.click_if_visible('div[aria-label="Close Modal"]')
20-
sb.click('button[data-testid="HOTELS_SUBMIT_BUTTON"]')
20+
sb.sleep(0.4)
21+
calendar_close = 'button[aria-label="Dismiss calendar"]'
22+
if not sb.is_element_visible(calendar_close):
23+
calendar_close = '[data-mode="range"] span.px-1'
24+
sb.click(calendar_close)
25+
sb.sleep(0.6)
26+
sb.click('form button[type="submit"]')
2127
sb.sleep(4.8)
2228
if len(sb.cdp.get_tabs()) > 1:
2329
sb.cdp.close_active_tab()
@@ -27,13 +33,24 @@
2733
for y in range(1, 9):
2834
sb.scroll_to_y(y * 400)
2935
sb.sleep(0.5)
30-
hotel_names = sb.find_elements('a[data-autobot-element-id*="HOTEL_NAME"]')
31-
if sb.is_element_visible('[font-size="4,,,5"]'):
32-
hotel_prices = sb.find_elements('[font-size="4,,,5"]')
33-
else:
36+
hotel_names = sb.find_elements('h3 div[class*="TitleName"]')
37+
if not hotel_names:
38+
hotel_names = sb.find_elements(
39+
'a[data-autobot-element-id*="HOTEL_NAME"]'
40+
)
41+
price_selector = '[class*="PriceWrap"] .relative > .items-center'
42+
if sb.is_element_visible(price_selector):
43+
hotel_prices = sb.find_elements(price_selector)
44+
elif sb.is_element_present(
45+
'[font-size="12px"] + [font-size="20px"]'
46+
):
3447
hotel_prices = sb.find_elements(
3548
'[font-size="12px"] + [font-size="20px"]'
3649
)
50+
else:
51+
hotel_prices = sb.find_elements(
52+
'span.text-priceSuper-heading4 + div > span'
53+
)
3754
print("Priceline Hotels in %s:" % location)
3855
print(sb.get_text('[data-testid="POPOVER-DATE-PICKER"]'))
3956
if len(hotel_names) == 0:
@@ -43,4 +60,6 @@
4360
if hotel_prices[i] and hotel_prices[i].text:
4461
count += 1
4562
hotel_price = "$" + hotel_prices[i].text
63+
if hotel_price.startswith("$$ "):
64+
hotel_price = hotel_price.replace("$$ ", "$")
4665
print("* %s: %s => %s" % (count, hotel.text, hotel_price))

examples/cdp_mode/raw_totalwine.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
sb.sleep(1.2)
1919
sb.press_keys(search_box, search)
2020
sb.sleep(0.6)
21+
sb.click_if_visible('button[aria-label="Close modal"]')
2122
sb.click('button[data-at="header-search-button"]')
2223
sb.sleep(1.8)
24+
sb.click_if_visible('button[aria-label="Close modal"]')
2325
sb.click('img[data-at="product-search-productimage"]')
2426
sb.sleep(2.2)
2527
print('*** Total Wine Search for "%s":' % search)
2628
print(sb.get_text('h1[data-at="product-name-title"]'))
27-
print(sb.get_text('span[data-at="product-mix6price-text"]'))
29+
print(sb.get_text('span[data-at="product-mixCaseprice-text"]'))
2830
print("Product Highlights:")
2931
print(sb.get_text('p[class*="productInformationReview"]'))
3032
print("Product Details:")

examples/cdp_mode/raw_united.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:
44
url = "https://www.united.com/en/us"
55
sb.activate_cdp_mode(url)
6-
sb.sleep(2.6)
6+
sb.sleep(3.5)
77
origin_input = 'input[placeholder="Origin"]'
8-
origin = "New York, NY"
8+
origin = "JFK"
99
destination_input = 'input[placeholder="Destination"]'
10-
destination = "Orlando, FL"
10+
destination = "MCO"
11+
sb.wait_for_element(origin_input, timeout=20)
12+
sb.sleep(0.5)
1113
sb.click(origin_input)
1214
sb.sleep(0.5)
1315
sb.type(origin_input, origin)
@@ -39,7 +41,7 @@
3941
part_3 = flight.text.split(" Destination")[-1].split(" Aircraft")[0]
4042
parts = "%s - %s %s" % (part_1, part_2, part_3)
4143
print("* " + parts)
42-
for category in ["ECONOMY", "ECONOMY-UNRESTRICTED"]:
44+
for category in ["ECONOMY"]:
4345
prices = sb.find_elements('[aria-describedby="%s"]' % category)
4446
full_prices = []
4547
for item in prices:

examples/cdp_mode/raw_zoro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
items = sb.find_elements('[data-za="search-product-card"]')
2525
for item in items:
2626
if required_text in item.text:
27-
description = item.querySelector('[data-za="product-title"]')
27+
description = item.querySelector("h2")
2828
if description and description.text not in unique_item_text:
2929
unique_item_text.append(description.text)
3030
print("* " + description.text)

examples/presenter/uc_presentation_4.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -769,26 +769,29 @@ def test_presentation_4(self):
769769
)
770770
self.begin_presentation(filename="uc_presentation.html")
771771

772-
with SB(
773-
uc=True, test=True, locale="en", guest=True, ad_block=True
774-
) as sb:
772+
with SB(uc=True, test=True, locale="en", guest=True, pls="none") as sb:
775773
url = "https://www.priceline.com"
776774
sb.activate_cdp_mode(url)
777-
sb.sleep(1.8)
778-
sb.click('input[name="endLocation"]')
775+
sb.sleep(2.6)
776+
input_selector = '[name="endLocation"]'
777+
if not sb.is_element_present(input_selector):
778+
input_selector = "div.location-input input"
779+
sb.click(input_selector)
779780
sb.sleep(1.2)
780-
location = "Portland, Oregon, US"
781+
location = "Portland, OR"
781782
selection = "Oregon, United States" # (Dropdown option)
782-
sb.press_keys('input[name="endLocation"]', location)
783-
sb.sleep(0.5)
784-
sb.click_if_visible('input[name="endLocation"]')
785-
sb.sleep(0.5)
783+
sb.press_keys(input_selector, location)
784+
sb.sleep(0.6)
786785
sb.click(selection)
786+
sb.sleep(0.4)
787787
sb.scroll_down(25)
788-
sb.click_if_visible('button[aria-label="Dismiss calendar"]')
789-
sb.click_if_visible("div.sidebar-iframe-close")
790-
sb.click_if_visible('div[aria-label="Close Modal"]')
791-
sb.click('button[data-testid="HOTELS_SUBMIT_BUTTON"]')
788+
sb.sleep(0.4)
789+
calendar_close = 'button[aria-label="Dismiss calendar"]'
790+
if not sb.is_element_visible(calendar_close):
791+
calendar_close = '[data-mode="range"] span.px-1'
792+
sb.click(calendar_close)
793+
sb.sleep(0.6)
794+
sb.click('form button[type="submit"]')
792795
sb.sleep(4.8)
793796
if len(sb.cdp.get_tabs()) > 1:
794797
sb.cdp.close_active_tab()
@@ -798,15 +801,24 @@ def test_presentation_4(self):
798801
for y in range(1, 9):
799802
sb.scroll_to_y(y * 400)
800803
sb.sleep(0.5)
801-
hotel_names = sb.find_elements(
802-
'a[data-autobot-element-id*="HOTEL_NAME"]'
803-
)
804-
if sb.is_element_visible('[font-size="4,,,5"]'):
805-
hotel_prices = sb.find_elements('[font-size="4,,,5"]')
806-
else:
804+
hotel_names = sb.find_elements('h3 div[class*="TitleName"]')
805+
if not hotel_names:
806+
hotel_names = sb.find_elements(
807+
'a[data-autobot-element-id*="HOTEL_NAME"]'
808+
)
809+
price_selector = '[class*="PriceWrap"] .relative > .items-center'
810+
if sb.is_element_visible(price_selector):
811+
hotel_prices = sb.find_elements(price_selector)
812+
elif sb.is_element_present(
813+
'[font-size="12px"] + [font-size="20px"]'
814+
):
807815
hotel_prices = sb.find_elements(
808816
'[font-size="12px"] + [font-size="20px"]'
809817
)
818+
else:
819+
hotel_prices = sb.find_elements(
820+
'span.text-priceSuper-heading4 + div > span'
821+
)
810822
print("Priceline Hotels in %s:" % location)
811823
print(sb.get_text('[data-testid="POPOVER-DATE-PICKER"]'))
812824
if len(hotel_names) == 0:
@@ -816,6 +828,8 @@ def test_presentation_4(self):
816828
if hotel_prices[i] and hotel_prices[i].text:
817829
count += 1
818830
hotel_price = "$" + hotel_prices[i].text
831+
if hotel_price.startswith("$$ "):
832+
hotel_price = hotel_price.replace("$$ ", "$")
819833
print("* %s: %s => %s" % (count, hotel.text, hotel_price))
820834

821835
self.create_presentation(theme="serif", transition="none")

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ exceptiongroup>=1.3.1
99
websockets~=15.0.1;python_version<"3.10"
1010
websockets>=16.0;python_version>="3.10"
1111
filelock~=3.19.1;python_version<"3.10"
12-
filelock>=3.25.1;python_version>="3.10"
12+
filelock>=3.25.2;python_version>="3.10"
1313
fasteners>=0.20
14-
mycdp>=1.3.3
14+
mycdp>=1.3.4
1515
pynose>=1.5.5
1616
platformdirs~=4.4.0;python_version<"3.10"
1717
platformdirs>=4.9.4;python_version>="3.10"

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.47.2"
2+
__version__ = "4.47.3"

0 commit comments

Comments
 (0)