From 2e20997fce637b9bc399ca47d2612faecd98a779 Mon Sep 17 00:00:00 2001 From: HK6 Date: Wed, 20 Nov 2024 12:05:17 -0800 Subject: [PATCH] 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. --- src/flaresolverr_service.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/flaresolverr_service.py b/src/flaresolverr_service.py index cfc2088..ee60f85 100644 --- a/src/flaresolverr_service.py +++ b/src/flaresolverr_service.py @@ -254,23 +254,16 @@ def _resolve_challenge(req: V1RequestBase, method: str) -> ChallengeResolutionT: def click_verify(driver: WebDriver): try: - logging.debug("Try to find the Cloudflare verify checkbox...") - iframe = driver.find_element(By.XPATH, "//iframe[starts-with(@id, 'cf-chl-widget-')]") - driver.switch_to.frame(iframe) - checkbox = driver.find_element( - by=By.XPATH, - value='//*[@id="content"]/div/div/label/input', - ) - if checkbox: + logging.debug("Try to check the Cloudflare verify checkbox...") + turnstileDiv = driver.find_element(By.XPATH, "//*[@id='cf-turnstile']") + if turnstileDiv: actions = ActionChains(driver) - actions.move_to_element_with_offset(checkbox, 5, 7) - actions.click(checkbox) + actions.move_to_element_with_offset(turnstileDiv, 34, 38) + actions.click() actions.perform() - logging.debug("Cloudflare verify checkbox found and clicked!") + logging.debug("Cloudflare verify checkbox click attempted!") except Exception: - logging.debug("Cloudflare verify checkbox not found on the page.") - finally: - driver.switch_to.default_content() + logging.debug("Cloudflare verify checkbox turnstile not found on the page.") try: logging.debug("Try to find the Cloudflare 'Verify you are human' button...")