Merge pull request #3407 from seleniumbase/cdp-mode-patch-24

CDP Mode - Patch 24
This commit is contained in:
Michael Mintz 2025-01-09 22:08:49 -05:00 committed by GitHub
commit b6d617e90c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 27 additions and 15 deletions

View File

@ -235,7 +235,7 @@ with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
url = "https://www.bestwestern.com/en_US.html"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
sb.cdp.click_if_visible("div.onetrust-close-btn-handler")
sb.cdp.click_if_visible(".onetrust-close-btn-handler")
sb.sleep(1)
sb.cdp.click("input#destination-input")
sb.sleep(2)
@ -250,7 +250,9 @@ with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
sb.sleep(2.5)
print("Best Western Hotels in %s:" % location)
summary_details = sb.cdp.get_text("#summary-details-column")
dates = summary_details.split("ROOM")[0].split("DATES")[-1].strip()
dates = summary_details.split("DESTINATION")[-1]
dates = dates.split(" CHECK-OUT")[0].strip() + " CHECK-OUT"
dates = dates.replace(" ", " ")
print("(Dates: %s)" % dates)
flip_cards = sb.cdp.select_all(".flipCard")
for i, flip_card in enumerate(flip_cards):

View File

@ -4,7 +4,7 @@ with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
url = "https://www.bestwestern.com/en_US.html"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
sb.cdp.click_if_visible("div.onetrust-close-btn-handler")
sb.cdp.click_if_visible(".onetrust-close-btn-handler")
sb.sleep(1)
sb.cdp.click("input#destination-input")
sb.sleep(2)
@ -19,7 +19,9 @@ with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
sb.sleep(2.5)
print("Best Western Hotels in %s:" % location)
summary_details = sb.cdp.get_text("#summary-details-column")
dates = summary_details.split("ROOM")[0].split("DATES")[-1].strip()
dates = summary_details.split("DESTINATION")[-1]
dates = dates.split(" CHECK-OUT")[0].strip() + " CHECK-OUT"
dates = dates.replace(" ", " ")
print("(Dates: %s)" % dates)
flip_cards = sb.cdp.select_all(".flipCard")
for i, flip_card in enumerate(flip_cards):

View File

@ -516,17 +516,19 @@ class UCPresentationClass(BaseCase):
)
self.begin_presentation(filename="uc_presentation.html")
with SB(uc=True, test=True, locale_code="en", ad_block=True) as sb:
with SB(uc=True, test=True, ad_block=True) as sb:
url = "https://www.walmart.com/"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
sb.cdp.click_if_visible('[data-automation-id*="close-mark"]')
sb.cdp.mouse_click('input[aria-label="Search"]')
sb.sleep(1.2)
search = "Settlers of Catan Board Game"
required_text = "Catan"
sb.cdp.press_keys('input[aria-label="Search"]', search + "\n")
sb.sleep(3.8)
print('\n\n*** Walmart Search for "%s":' % search)
sb.cdp.remove_elements('[data-testid="skyline-ad"]')
print('*** Walmart Search for "%s":' % search)
print(' (Results must contain "%s".)' % required_text)
unique_item_text = []
items = sb.cdp.find_elements('div[data-testid="list-view"]')
@ -642,7 +644,7 @@ class UCPresentationClass(BaseCase):
sb.cdp.click('button[data-testid="submit"]')
sb.sleep(3.5)
sb.connect()
sb.sleep(2.5)
sb.sleep(4.2)
for window in sb.driver.window_handles:
sb.switch_to_window(window)
if "/buy/flights" in sb.get_current_url():
@ -708,6 +710,7 @@ class UCPresentationClass(BaseCase):
if "Avg/Night" in info and not info.startswith("Rates from"):
name = info.split(" (")[0]
name = name.split(" + ")[0].split(" Award Cat")[0]
name = name.split(" Rates from :")[0]
price = "?"
if "Rates from : " in info:
price = info.split("Rates from : ")[1]
@ -728,7 +731,7 @@ class UCPresentationClass(BaseCase):
url = "https://www.bestwestern.com/en_US.html"
sb.activate_cdp_mode(url)
sb.sleep(2.5)
sb.cdp.click_if_visible("div.onetrust-close-btn-handler")
sb.cdp.click_if_visible(".onetrust-close-btn-handler")
sb.sleep(1)
sb.cdp.click("input#destination-input")
sb.sleep(2)
@ -741,9 +744,11 @@ class UCPresentationClass(BaseCase):
sb.sleep(4)
sb.cdp.click("label#available-label")
sb.sleep(2.5)
print("\n\nBest Western Hotels in %s:" % location)
print("Best Western Hotels in %s:" % location)
summary_details = sb.cdp.get_text("#summary-details-column")
dates = summary_details.split("ROOM")[0].split("DATES")[-1].strip()
dates = summary_details.split("DESTINATION")[-1]
dates = dates.split(" CHECK-OUT")[0].strip() + " CHECK-OUT"
dates = dates.replace(" ", " ")
print("(Dates: %s)" % dates)
flip_cards = sb.cdp.select_all(".flipCard")
for i, flip_card in enumerate(flip_cards):

View File

@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.33.13"
__version__ = "4.33.14"

View File

@ -1544,6 +1544,9 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
for i in range(10):
pyautogui.hotkey("shift", "tab")
time.sleep(0.027)
if ctype == "g_rc":
if js_utils.get_active_element_css(driver) == "body":
break
tab_count = 0
for i in range(34):
pyautogui.press("\t")

View File

@ -187,7 +187,7 @@ class Patcher(object):
with io.open(executable_path, "rb") as fh:
if re.search(
b"window.cdc_adoQpoasnfa76pfcZLmcfl_"
b"(Array|Promise|Symbol|Object|Proxy|JSON)",
b"(Array|Promise|Symbol|Object|Proxy|JSON|Window)",
fh.read()
):
return False
@ -210,14 +210,14 @@ class Patcher(object):
file_bin = fh.read()
file_bin = re.sub(
b"window\\.cdc_[a-zA-Z0-9]{22}_"
b"(Array|Promise|Symbol|Object|Proxy|JSON)"
b" = window\\.(Array|Promise|Symbol|Object|Proxy|JSON);",
b"(Array|Promise|Symbol|Object|Proxy|JSON|Window) "
b"= window\\.(Array|Promise|Symbol|Object|Proxy|JSON|Window);",
gen_js_whitespaces,
file_bin,
)
file_bin = re.sub(
b"window\\.cdc_[a-zA-Z0-9]{22}_"
b"(Array|Promise|Symbol|Object|Proxy|JSON) \\|\\|",
b"(Array|Promise|Symbol|Object|Proxy|JSON|Window) \\|\\|",
gen_js_whitespaces,
file_bin,
)