Solve hCaptcha in Selenium

Selenium drives the browser. VanishCaptcha returns the token. You write that token into the hidden response field and continue the flow you already had.

Steps

  1. Open the page and read data-sitekey from the widget.
  2. Request a token with the Python client. Use the same page URL the browser is on.
  3. Inject the token into h-captcha-response and g-recaptcha-response, then submit the form.
python
from selenium import webdriver
from vanishcaptcha import VanishCaptcha

driver = webdriver.Chrome()
driver.get("https://example.com/login")
sitekey = driver.find_element("css selector", "[data-sitekey]").get_attribute("data-sitekey")

solve = VanishCaptcha(api_key="nc_live_...").solve(
    type="hcaptcha",
    sitekey=sitekey,
    url=driver.current_url,
)

driver.execute_script(
    """
    const token = arguments[0];
    for (const name of ["h-captcha-response", "g-recaptcha-response"]) {
      const el = document.querySelector('[name="' + name + '"]');
      if (el) { el.value = token; el.innerHTML = token; }
    }
    """,
    solve.token,
)

Enterprise rqdata

If the widget carries rqdata, send type: "hcaptcha_enterprise" and that value. The token that comes back is what the enterprise sitekey expects. Fields are in the API reference.

Questions

Does this solve reCAPTCHA or Turnstile?
No. These guides are hCaptcha only. reCAPTCHA and Turnstile are not live on VanishCaptcha.
How long is the token good for?
About two minutes, and it can be submitted once. Request it immediately before the form goes out.

Start solving hCaptcha in minutes.

1,400 free credits on signup. Pay per solve, credits never expire, failed solves never charged.