Blindly click CloudFlare verify checkbox

The CloudFlare verification checkbox is now in a #shadow-root (closed), which means you can't find any of the elements. Easiest solution is to find the outer turnstile element and blindly click it.
This commit is contained in:
HK6 2024-11-20 12:05:17 -08:00 committed by GitHub
parent 54668a11e7
commit 2e20997fce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -254,23 +254,16 @@ def _resolve_challenge(req: V1RequestBase, method: str) -> ChallengeResolutionT:
def click_verify(driver: WebDriver): def click_verify(driver: WebDriver):
try: try:
logging.debug("Try to find the Cloudflare verify checkbox...") logging.debug("Try to check the Cloudflare verify checkbox...")
iframe = driver.find_element(By.XPATH, "//iframe[starts-with(@id, 'cf-chl-widget-')]") turnstileDiv = driver.find_element(By.XPATH, "//*[@id='cf-turnstile']")
driver.switch_to.frame(iframe) if turnstileDiv:
checkbox = driver.find_element(
by=By.XPATH,
value='//*[@id="content"]/div/div/label/input',
)
if checkbox:
actions = ActionChains(driver) actions = ActionChains(driver)
actions.move_to_element_with_offset(checkbox, 5, 7) actions.move_to_element_with_offset(turnstileDiv, 34, 38)
actions.click(checkbox) actions.click()
actions.perform() actions.perform()
logging.debug("Cloudflare verify checkbox found and clicked!") logging.debug("Cloudflare verify checkbox click attempted!")
except Exception: except Exception:
logging.debug("Cloudflare verify checkbox not found on the page.") logging.debug("Cloudflare verify checkbox turnstile not found on the page.")
finally:
driver.switch_to.default_content()
try: try:
logging.debug("Try to find the Cloudflare 'Verify you are human' button...") logging.debug("Try to find the Cloudflare 'Verify you are human' button...")