Skip to content
Programmatic guide

hCaptcha solver for Selenium Python

Solve hCaptcha from Selenium Python in two API calls. Token injection works in headless and headed Chrome / Firefox alike.

Python · Selenium

Runnable example

from captchasonic import CaptchaSonic
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://accounts.hcaptcha.com/demo')

sonic = CaptchaSonic('YOUR_API_KEY')
result = sonic.solve(
    type='HCaptchaTaskProxyless',
    website_url=driver.current_url,
    website_key='10000000-ffff-ffff-ffff-000000000001',
)

driver.execute_script(
    """
    document.querySelector('[name=h-captcha-response]').value = arguments[0];
    document.querySelector('[name=g-recaptcha-response]').value = arguments[0];
    """,
    result.token,
)
driver.find_element('css selector', 'form button[type=submit]').click()

Replace YOUR_API_KEY with a real key from your dashboard. The token is good for one form submission.

FAQ

Does Selenium need undetected-chromedriver for hCaptcha?
For standard hCaptcha — usually no, the token approach avoids the fingerprint check. For Enterprise hCaptcha on aggressive sites, undetected-chromedriver helps the surrounding session blend in.
Where do I find the websiteKey?
Inspect the page for the [data-sitekey] attribute on the h-captcha div, or search the page source for "sitekey" — it's a UUID-shaped string.
Why set both h-captcha-response and g-recaptcha-response?
hCaptcha is a drop-in replacement for reCAPTCHA; many backends still read the legacy g-recaptcha-response field. Setting both covers either implementation without behavioral risk.

How CaptchaSonic compares for this captcha

Feature-by-feature against the four most-mentioned alternatives. Independently benchmarked; numbers refresh quarterly.

FeatureCaptchaSonic2CaptchaCapSolverAnti-CaptchaCapMonster Cloud
AI / ML solver (no human relay)
hCaptcha (incl. Enterprise)
Success rate (trailing 30d)99.9%~95%~98%~95%~97%
Price per 1k — hCaptcha$0.90$2.99$1.20$2.00$1.50
Proxy + proxyless modes
Free trial credits
SDK languages (Py, Node, Go, C#, Java, PHP)66454
Selenium / Puppeteer / Playwright examples
Browser extension
Webhook callbacks
99.9% uptime SLA

Yes / No / Partial reflect publicly documented support. Pricing and solve-time figures snapshot the published rate at the time this page was last updated.

Related guides