Can I bypass Recaptcha in the form

111 views
Skip to first unread message

Nikita Chavan

unread,
Apr 21, 2025, 11:05:10 AMApr 21
to Selenium Users
Hi,

I am trying to automate form and stuck at Recaptcha. I could able to tick the checkbox but how should I bypass the image validating?

Is that doable? 

In Advance: Thanks for your help!

ddlionx

unread,
Apr 21, 2025, 11:20:16 AMApr 21
to seleniu...@googlegroups.com
In the test version of what you are automating you can use 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/selenium-users/f27b2d21-2cbc-4bb2-b522-1279f01aeccen%40googlegroups.com.

Corey Goldberg

unread,
Apr 21, 2025, 12:17:57 PMApr 21
to seleniu...@googlegroups.com
> how should I bypass the image validating?

You can't. Their purpose is to determine if you are human.

If this is your own site, disable CAPTCHA in your test environment.



--

Nikita Chavan

unread,
Apr 22, 2025, 12:12:06 AMApr 22
to Selenium Users
Thanks a lot all. I will try it on test environment instead of prod by disabling recaptcha.

Artur Oliveira Carvalho

unread,
Jun 29, 2025, 10:28:50 AMJun 29
to Selenium Users

Actually, you can bypass recaptcha using a third party service called 2Captcha, but it's a paid service. I use and recommend this service, but in some cases (callback recaptcha), you'll need to implement some tools to set the response like:


log = LoggerFactory.get_stream_logger('CaptchaSolver')

FLATTEN_OBJECT_SCRIPT = 'window._flattenObject=function(e,t=2,n=!0){const c=e=>e&&"object"==typeof e,o=e=>e&&e instanceof HTMLElement;let f={};for(let r=0;r<t;r++)e=Object.keys(f).length?f:e,Object.keys(e).forEach(t=>{n&&o(e[t])||(c(e[t])?Object.keys(e[t]).forEach(r=>{if(n&&o(e[t][r]))return;const b=c(e[t][r])?`obj_${t}_${r}`:`${r}`;f[b]=e[t][r]}):f[t]=e[t])});return f};'
DATA_RECAPTCHA_SCRIPT = 'return window._flattenObject(window.___grecaptcha_cfg.clients[0]);'
SET_RESPONSE_SCRIPT = 'arguments[0].innerHTML = arguments[1];'
CALLBACK_SCRIPT = 'var flat = window._flattenObject(window.___grecaptcha_cfg.clients[0]); if (flat.callback) {flat.callback.call(window, arguments[0]);}'


class CaptchaSolver:
def __init__(self) -> None:
self.solver = twocaptcha.TwoCaptcha(**{
'apiKey': os.environ.get('TWO_CAPTCHA_KEY', default='<YOUR_API_KEY>'),
'defaultTimeout': 120,
'recaptchaTimeout': 600,
'pollingInterval': 10,
})

def solve_captcha(self, driver: WebDriver):
if not DriverUtils.is_headless(driver):
log.info('solving the captcha using the screen')
return input('Solved?')
log.info('trying to solve captcha')
driver.execute_script(FLATTEN_OBJECT_SCRIPT)

response: Dict[str, Any] = self.solver.recaptcha(
sitekey=driver.execute_script(DATA_RECAPTCHA_SCRIPT).get('sitekey'),
url=driver.current_url
)

log.info(f'RECAPTCHA RESPONSE: {response}')

g_captcha = DriverUtils.find_by_tag(driver, 'textarea')
driver.execute_script(SET_RESPONSE_SCRIPT, g_captcha, response.get('code'))

try:
driver.execute_script(CALLBACK_SCRIPT, response.get('code'))
except Exception:
...

log.info('solved captcha')
Reply all
Reply to author
Forward
0 new messages