1

I need to bypass the cloudflare challenge while uploading images but I am not able to bypass it. I have tried many concepts but still i am not able to get the resolve the issue.

What I need when the cloudflare is displayes it should automatically click the checkbox until how many times it was asking if it askes for 25 times it should check the box until the next visibity of the next element:

I just updated the code but still i am not able to click on the field

Facing Issue here is :

Traceback (most recent call last):

  File "C:\Users\yazha\AppData\Roaming\JetBrains\PyCharmCE2023.1\scratches\scratch_6.py", line 14, in <module>

    cf_element = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "label.ctp-checkbox-label")))

  File "D:\Python files\undetected-chromedriver-master\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 95, in until

    raise TimeoutException(message, screen, stacktrace)

selenium.common.exceptions.TimeoutException: Message:

Cloudflare challenge:

enter image description here

enter image description here - cloudflare element

enter image description here - finding the next element

Code trials:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

# Initialize webdriver
driver = webdriver.Chrome()
driver.maximize_window()
# Open Redbubble website and click on login
driver.get('redbubble url')
wait = WebDriverWait(driver, 20)
cf_element = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "label.ctp-checkbox-label")))
num_attempts = 0
while True:
    try:
        cf_element.click()
        num_attempts += 1
        wait.until(EC.invisibility_of_element(cf_element))
        cf_element = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "select-image-single")))
    except Exception as e:
        print(f"Cloudflare captcha bypassed {num_attempts} times.")
        break
# Continue with your code after bypassing the captcha
driver.get(the redbubble url)
time.sleep(20)
driver.find_element(By.ID, "select-image-single").click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

1

Here's a complete SeleniumBase script for bypassing Cloudflare.

pip install seleniumbase, then run with python:

from seleniumbase import SB

def verify_success(sb):
    sb.assert_text("OH YEAH, you passed!", "h1", timeout=6.25)
    sb.post_message("Selenium wasn't detected!", duration=2.8)
    sb._print("\n Success! Website did not detect Selenium! ")

with SB(uc=True, incognito=True) as sb:
    sb.open("https://nowsecure.nl/#relax")
    try:
        verify_success(sb)
    except Exception:
        sb.get_new_driver(undetectable=True, incognito=True)
        sb.open("https://nowsecure.nl/#relax")
        try:
            verify_success(sb)
        except Exception:
            if sb.is_element_visible('iframe[src*="challenge"]'):
                with sb.frame_switch('iframe[src*="challenge"]'):
                    sb.click("area")
            else:
                raise Exception("Detected!")
            try:
                verify_success(sb)
            except Exception:
                raise Exception("Detected!")

It will click the checkbox if necessary. Use sb.driver to access the raw driver.

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
1

The enabled checkbox associated with the text Verify you are human element is within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following locator strategies:

    • Using CSS_SELECTOR:

      driver.get("https://www.redbubble.com/portfolio/images/new")
      time.sleep(5)
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[title='Widget containing a Cloudflare security challenge']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label.ctp-checkbox-label"))).click()
      
    • Using XPATH:

      driver.get("https://www.redbubble.com/portfolio/images/new")
      time.sleep(5)
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@title='Widget containing a Cloudflare security challenge']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@class='ctp-checkbox-label']"))).click()
      
  • Note : You have to add the following imports :

     from selenium.webdriver.support.ui import WebDriverWait
     from selenium.webdriver.common.by import By
     from selenium.webdriver.support import expected_conditions as EC
    
  • Browser snapshot:

redbubble


Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352