Captcha solver for
Selenium
Resolve the challenge inside the run instead of failing the job. A working Python example, and the three things that decide whether your token is accepted.
import time
import requests
CAPTCHANO_KEY = "cn-YOUR_API_KEY"
HEADERS = {"Authorization": f"Bearer {CAPTCHANO_KEY}"}
def solve(task: dict) -> dict:
"""Block until solved; returns e.g. {"token": "...", "userAgent": "..."}."""
r = requests.post(
"https://api.captchano.com/v1/solve",
params={"wait": 60},
json=task,
headers=HEADERS,
timeout=75,
)
data = r.json()
# A solve can outlast the 60 s wait: poll the task until it finishes.
while data.get("status") in ("queued", "solving"):
time.sleep(5)
data = requests.get(
f"https://api.captchano.com/v1/task/{data['id']}",
headers=HEADERS,
timeout=30,
).json()
if data.get("status") != "ready":
raise RuntimeError(data.get("error") or data)
return data["solution"]
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://example.com/login")
sitekey = driver.find_element(By.CSS_SELECTOR, "[data-sitekey]").get_attribute("data-sitekey")
solution = solve({"type": "recaptcha_v2", "sitekey": sitekey, "url": driver.current_url})
driver.execute_script(
"document.getElementById('g-recaptcha-response').value = arguments[0]",
solution["token"],
)
driver.find_element(By.CSS_SELECTOR, "form").submit()What decides whether the token is accepted
- Pass your proxy through. The token should be minted behind the same exit IP that submits it. For session-graded systems this is mandatory, not an optimisation.
- Match the user agent. Turnstile and several anti-bot systems bind the token to a user agent. We return the one used so you can replay it exactly.
- Request late. Tokens expire in roughly 120 seconds. Ask for one when you are ready to submit.
Blocking or polling
The example uses ?wait=60, so the call returns the finished solve and your Selenium step stays linear. If you would rather not hold a connection, drop the parameter, keep the returned id, and poll GET /v1/task/{id} every five seconds. A token you have paid for stays retrievable for ten minutes, so a dropped connection does not cost you the solve.
Cost
$0.00598 per successful reCAPTCHA v2 solve, with failed solves never billed. See pricing for every challenge type, or the API reference for the full request shape.
How the solve fits into Selenium
Selenium drives a real browser, so the challenge renders exactly as a user would see it. Read the sitekey from the DOM, request a token, and write it back with execute_script before you click submit.
- 01Load the page
Open the target with the proxy and user agent you will submit from.
- 02Read the sitekey
find_element by [data-sitekey] and read the attribute, plus data-callback if present.
- 03Solve
POST type, sitekey and driver.current_url to /v1/solve?wait=60 with the same proxy and user agent.
- 04Inject and submit
execute_script to fill the response field and fire the callback, then click submit.
Getting the token into the page
driver.execute_script sets the hidden g-recaptcha-response or cf-turnstile-response field and, where the page uses one, calls the widget's callback.
Where integrations usually go wrong
Many pages enable the submit button from the widget callback. Filling the field alone leaves the button disabled.
The response textarea is created when the widget renders. Wait for the widget iframe before you inject.
Selenium's proxy is set at driver start. Pass the same proxy string to the solve so the token and the submit share an IP.
Selenium captcha FAQ
Can Selenium solve reCAPTCHA by itself?
No. Selenium controls the browser but cannot answer an image challenge, and automated browsers are more likely to be shown one. You request a token from a solving API and inject it, as the example on this page does.
Does this work with undetected-chromedriver or Selenium Grid?
Yes. The integration only reads the DOM and runs JavaScript, so it works with any WebDriver session, local or remote, as long as you pass the same proxy and user agent to the solve.
Where do I put the token for Turnstile?
Turnstile uses a hidden input named cf-turnstile-response inside the form. Set its value and call the callback named in data-callback if the page declares one.
How do I handle a captcha that appears only sometimes?
Check for the widget after each navigation and only call the API when it is present. You are billed per successful solve, so checking costs nothing.
Guides that help
Ready to build?
Start with a free 7-day trial of the Hobby plan, then pay per successful solve or keep the plan as your traffic grows. Cancel before the trial ends and you pay nothing.