From fda2ffe865c6757ace96a5356093df593935ffb2 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Fri, 2 Aug 2024 18:46:50 -0400 Subject: [PATCH] Update examples --- examples/raw_cdp_logging.py | 2 +- examples/raw_form_turnstile.py | 2 +- examples/raw_gui_click.py | 7 ++----- examples/raw_pyautogui.py | 7 ++----- examples/raw_recaptcha.py | 10 +++++++++- examples/uc_cdp_events.py | 2 +- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/examples/raw_cdp_logging.py b/examples/raw_cdp_logging.py index 1f9c7659..23ae0b17 100644 --- a/examples/raw_cdp_logging.py +++ b/examples/raw_cdp_logging.py @@ -5,7 +5,7 @@ driver = Driver(uc=True, log_cdp=True) try: url = "seleniumbase.io/apps/turnstile" driver.uc_open_with_reconnect(url, 2) - driver.uc_gui_handle_cf() + driver.uc_gui_handle_captcha() driver.sleep(3) pprint(driver.get_log("performance")) finally: diff --git a/examples/raw_form_turnstile.py b/examples/raw_form_turnstile.py index 8e7bf6b7..0ff1be0f 100644 --- a/examples/raw_form_turnstile.py +++ b/examples/raw_form_turnstile.py @@ -13,7 +13,7 @@ with SB(uc=True, test=True) as sb: sb.highlight_click('input[value="AR"] + span') sb.click('input[value="cc"] + span') sb.scroll_to('div[class*="cf-turnstile"]') - sb.uc_gui_handle_cf() + sb.uc_gui_handle_captcha() sb.highlight("img#captcha-success", timeout=3) sb.highlight_click('button:contains("Request & Pay")') sb.highlight("img#submit-success") diff --git a/examples/raw_gui_click.py b/examples/raw_gui_click.py index f4dabb05..fb46fe74 100644 --- a/examples/raw_gui_click.py +++ b/examples/raw_gui_click.py @@ -1,10 +1,7 @@ -""" -UC Mode now has uc_gui_click_cf(), which uses PyAutoGUI. -An incomplete UserAgent forces CAPTCHA-solving on macOS. -""" import sys from seleniumbase import SB +# An incomplete UserAgent forces CAPTCHA-solving on macOS agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/126.0.0.0" if "linux" in sys.platform or "win32" in sys.platform: agent = None # Use the default UserAgent @@ -12,7 +9,7 @@ if "linux" in sys.platform or "win32" in sys.platform: with SB(uc=True, test=True, rtf=True, agent=agent) as sb: url = "https://gitlab.com/users/sign_in" sb.uc_open_with_reconnect(url, 4) - sb.uc_gui_click_cf() # Ready if needed! + sb.uc_gui_click_captcha() # Only if needed sb.assert_element('label[for="user_login"]') sb.assert_element('input[data-testid*="username"]') sb.assert_element('input[data-testid*="password"]') diff --git a/examples/raw_pyautogui.py b/examples/raw_pyautogui.py index 75616d2a..7bc4eb27 100644 --- a/examples/raw_pyautogui.py +++ b/examples/raw_pyautogui.py @@ -1,10 +1,7 @@ -""" -UC Mode now has uc_gui_handle_cf(), which uses PyAutoGUI. -An incomplete User-Agent forces CAPTCHA-solving on macOS. -""" import sys from seleniumbase import SB +# An incomplete UserAgent forces CAPTCHA-solving on macOS agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/126.0.0.0" if "linux" in sys.platform or "win32" in sys.platform: agent = None # Use the default UserAgent @@ -12,7 +9,7 @@ if "linux" in sys.platform or "win32" in sys.platform: with SB(uc=True, test=True, rtf=True, agent=agent) as sb: url = "https://gitlab.com/users/sign_in" sb.uc_open_with_reconnect(url, 4) - sb.uc_gui_handle_cf() # Ready if needed! + sb.uc_gui_handle_captcha() # Only if needed sb.assert_element('label[for="user_login"]') sb.assert_element('input[data-testid*="username"]') sb.assert_element('input[data-testid*="password"]') diff --git a/examples/raw_recaptcha.py b/examples/raw_recaptcha.py index c348bfdc..a9a35e32 100644 --- a/examples/raw_recaptcha.py +++ b/examples/raw_recaptcha.py @@ -3,7 +3,15 @@ from seleniumbase import SB with SB(uc=True, test=True) as sb: url = "https://seleniumbase.io/apps/recaptcha" sb.uc_open_with_reconnect(url) - sb.uc_gui_click_captcha() + sb.uc_gui_handle_captcha() # Try with TAB + SPACEBAR + sb.assert_element("img#captcha-success", timeout=3) + sb.set_messenger_theme(location="top_left") + sb.post_message("SeleniumBase wasn't detected", duration=3) + +with SB(uc=True, test=True) as sb: + url = "https://seleniumbase.io/apps/recaptcha" + sb.uc_open_with_reconnect(url) + sb.uc_gui_click_captcha() # Try with PyAutoGUI Click sb.assert_element("img#captcha-success", timeout=3) sb.set_messenger_theme(location="top_left") sb.post_message("SeleniumBase wasn't detected", duration=3) diff --git a/examples/uc_cdp_events.py b/examples/uc_cdp_events.py index d869c751..6fcaf2c2 100644 --- a/examples/uc_cdp_events.py +++ b/examples/uc_cdp_events.py @@ -13,7 +13,7 @@ class CDPTests(BaseCase): ) def click_turnstile_and_verify(sb): - sb.uc_gui_handle_cf() + sb.uc_gui_handle_captcha() sb.assert_element("img#captcha-success", timeout=3) sb.highlight("img#captcha-success", loops=8)