Merge pull request #2967 from seleniumbase/handle-form-captchas

Handle update to form turnstiles
This commit is contained in:
Michael Mintz 2024-07-26 14:45:43 -04:00 committed by GitHub
commit 025572dc16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 12 deletions

View File

@ -4,10 +4,11 @@ with SB(uc=True, test=True, incognito=True, locale_code="en") as sb:
url = "https://ahrefs.com/website-authority-checker"
input_field = 'input[placeholder="Enter domain"]'
submit_button = 'span:contains("Check Authority")'
sb.driver.uc_open_with_reconnect(url, 2) # The bot-check is later
sb.uc_open_with_reconnect(url, 2) # The bot-check is later
sb.type(input_field, "github.com/seleniumbase/SeleniumBase")
sb.driver.reconnect(0.1)
sb.driver.uc_click(submit_button, reconnect_time=4)
sb.reconnect(0.1)
sb.uc_click(submit_button, reconnect_time=4)
sb.uc_gui_click_captcha()
sb.wait_for_text_not_visible("Checking", timeout=10)
sb.highlight('p:contains("github.com/seleniumbase/SeleniumBase")')
sb.highlight('a:contains("Top 100 backlinks")')

View File

@ -12,7 +12,7 @@ with SB(uc=True, test=True) as sb:
sb.click('span:contains("9:00 PM")')
sb.highlight_click('input[value="AR"] + span')
sb.click('input[value="cc"] + span')
sb.scroll_to("div.cf-turnstile-wrapper")
sb.scroll_to('div[class*="cf-turnstile"]')
sb.uc_gui_handle_cf()
sb.highlight("img#captcha-success", timeout=3)
sb.highlight_click('button:contains("Request & Pay")')

View File

@ -3,13 +3,11 @@ from seleniumbase import SB
with SB(uc=True, test=True, disable_csp=True) as sb:
url = "https://steamdb.info/"
sb.driver.uc_open_with_reconnect(url, 3)
sb.uc_click("a.header-login span", 4)
if not sb.is_text_visible("Sign in", "button#js-sign-in"):
sb.driver.uc_open_with_reconnect(url, 3)
sb.uc_click("a.header-login span", 4)
sb.uc_open_with_reconnect(url, 3)
sb.uc_click("a.header-login span", 3)
sb.uc_gui_click_captcha()
sb.assert_text("Sign in", "button#js-sign-in", timeout=3)
sb.driver.uc_click("button#js-sign-in", 2)
sb.uc_click("button#js-sign-in", 2)
sb.highlight("div.page_content form")
sb.highlight('button:contains("Sign in")', scroll=False)
sb.set_messenger_theme(location="top_center")

View File

@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.29.2"
__version__ = "4.29.3"

View File

@ -812,6 +812,16 @@ def _uc_gui_click_captcha(
and driver.is_element_present("div.spacer div[style]")
):
frame = "div.spacer div[style]"
elif (
(
driver.is_element_present('[name*="cf-turnstile-"]')
or driver.is_element_present('[id*="cf-turnstile-"]')
)
and driver.is_element_present(
'form div div[style*="margin"][style*="padding"]'
)
):
frame = 'form div div[style*="margin"][style*="padding"]'
elif (
frame != "iframe"
and driver.is_element_present(
@ -1017,7 +1027,7 @@ def uc_gui_handle_cf(driver, frame="iframe"):
time.sleep(0.02)
active_element_css = js_utils.get_active_element_css(driver)
if (
active_element_css == "div.cf-turnstile-wrapper"
active_element_css.startswith("div.cf-turnstile")
or active_element_css.startswith("div#PYMIw2")
):
found_checkbox = True