
Solving CAPTCHAs in Selenium Tests Without Slowing Down CI
If you've ever built E2E tests with Selenium, you've hit this wall: your test suite runs perfectly until a login page throws up a reCAPTCHA, and suddenly your CI pipeline is broken. Here are three approaches I've used, with honest pros and cons for each. Approach 1: Disable CAPTCHAs in Test Environments The simplest fix — just turn them off. # Django example: settings_test.py RECAPTCHA_TESTING = True # Or use an env flag # CAPTCHA_ENABLED=false pytest When it works: Internal apps where you control the backend. When it doesn't: Testing against third-party sites, or when you need to verify the CAPTCHA integration itself works in production. Approach 2: Try to Click Through It from selenium.webdriver.common.by import By # Switch to reCAPTCHA iframe iframe = driver . find_element ( By . CSS_SELECTOR , " iframe[src*= ' recaptcha ' ] " ) driver . switch_to . frame ( iframe ) # Click the checkbox checkbox = driver . find_element ( By . CLASS_NAME , " recaptcha-checkbox " ) checkbox . click ()
Continue reading on Dev.to
Opens in a new tab



