NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

Integration guide

Selenium integration: reCAPTCHA v2 and Turnstile in Python and Java

Selenium drives the browser and GateSolver supplies the answer the widget would have produced. This guide is the full reference for both languages, from explicit waits to callbacks and Grid scale.

How the pieces fit

Selenium never solves anything itself in this setup. Your test or job opens the page, reads the widget's public parameters, and hands them to the GateSolver HTTP API as a task. A few seconds later the API returns a token, your code writes it into the field the widget would have filled, and the form is submitted as usual. There is no plugin to install on our side: two POST requests and a little JavaScript inside the page are the whole integration.

This guide covers the two widgets Selenium users meet most on forms: the reCAPTCHA v2 checkbox, billed at $0.56 per 1,000, and Cloudflare Turnstile at $0.84 per 1,000. Both return in roughly the same time (under 9 seconds for the checkbox), and both are charged only when a token is delivered. The same structure carries over to any other token type listed under CAPTCHA types.

Prerequisites and installation

  • Python: Python 3.9 or newer, then pip install selenium requests. Selenium 4.6 and later ship Selenium Manager, which downloads a matching ChromeDriver on first run, so a separate driver download is usually unnecessary.
  • Java: JDK 11 or newer (for the built in java.net.http client), the org.seleniumhq.selenium:selenium-java artifact and a JSON library. The example uses Jackson (com.fasterxml.jackson.core:jackson-databind); Gson works just as well.
  • An API key from your account page, stored in an environment variable such as GATESOLVER_KEY rather than in source control, and a balance topped up from $40.

Check the Selenium release notes for the version you install; method names below match the 4.x line at the time of writing.

Reading the widget with explicit waits

Wait for the widget element, never for a fixed number of seconds. Widgets are often injected after the form renders, so find_element called right after get() can fail on a slow page and pass on a fast one, which makes tests flaky. WebDriverWait with presence_of_element_located polls the DOM until the element exists or the timeout ends.

Both widgets usually sit in a container with a data-sitekey attribute. The class tells you which one you have: g-recaptcha for Google's checkbox, cf-turnstile for Cloudflare. A Turnstile key starts with 0x4, a reCAPTCHA key usually with 6L. Read two more attributes while you are there. data-callback names the JavaScript function the page expects to receive the answer, and on Turnstile data-action or data-cdata, when present, must go into the task's metadata object. If the container has no key because the page calls a render function from script, the methods in finding the reCAPTCHA site key still apply.

The complete Python example

The script below detects which widget is present, solves it, places the token, calls the callback when one is declared, and waits for the page to move on. It is written as one file so you can run it against a page you own before splitting it into your project's helpers.

import os, requests, time
import selenium.webdriver.support.expected_conditions as conditions
from selenium.webdriver import Chrome
from selenium.webdriver.support.wait import WebDriverWait as PageWait
CSS = "css selector"  # same value as By.CSS_SELECTOR

SOLVER_ROOT = "https://gatesolver.com"
SELENIUM_KEY = os.environ.get("GATESOLVER_KEY", "YOUR_API_KEY")
WIDGETS = ".g-recaptcha[data-sitekey], .cf-turnstile[data-sitekey]"
def ask_solver(route, **fields):
    data = requests.post(f"{SOLVER_ROOT}/{route}", timeout=30,
                         json={"clientKey": SELENIUM_KEY, **fields}).json()
    if data.get("errorId"):
        raise RuntimeError(data.get("errorCode", "unnamed API error"))
    return data
def answer_widget(box, page_url):
    turnstile = "cf-turnstile" in box.get_dom_attribute("class")
    kind = "AntiTurnstileTaskProxyLess" if turnstile else "ReCaptchaV2TaskProxyLess"
    job = ask_solver("createTask", task={"type": kind, "websiteURL": page_url,
                                         "websiteKey": box.get_dom_attribute("data-sitekey")})
    for _ in range(40):
        time.sleep(3)
        snap = ask_solver("getTaskResult", taskId=job["taskId"])
        if snap["status"] == "ready":
            found = snap["solution"]
            return found.get("token") or found.get("gRecaptchaResponse"), turnstile
        if snap["status"] == "failed":
            raise RuntimeError("solve failed, nothing was billed")
    raise TimeoutError("widget answer did not arrive")
PLACE_ANSWER = """const [box, value, ts] = arguments;
const field = (ts ? 'cf-turnstile' : 'g-recaptcha') + '-response';
document.querySelectorAll(`[name="${field}"]`).forEach((el) => { el.value = value; });
const hook = box.getAttribute('data-callback');
if (hook && typeof window[hook] === 'function') window[hook](value);"""

browser = Chrome()
waiter = PageWait(browser, 20)
browser.get("https://example.com/contact")
widget = waiter.until(conditions.presence_of_element_located((CSS, WIDGETS)))
answer, is_ts = answer_widget(widget, browser.current_url)
browser.execute_script(PLACE_ANSWER, widget, answer, is_ts)
browser.find_element(CSS, "form [type=submit]").click()
waiter.until(conditions.url_changes("https://example.com/contact"))
browser.quit()

Callbacks: why the button stays disabled

Writing the token into the hidden field is enough for a plain HTML form, because the browser posts every named field. Many modern forms are not plain: they keep the submit button disabled, or they send the request themselves, and they only react when the widget calls their JavaScript function. In that case the field holds a valid token but nothing happens on click. The data-callback lookup in the example solves the common case. When the function is registered through grecaptcha.render(el, {callback: fn}) instead of an attribute, the name is not in the DOM; our guide to finding the reCAPTCHA callback shows how to locate it in the page's configuration object. Turnstile works the same way with its own data-callback attribute or render option.

The Java version

Java teams can keep the API calls inside the test class or move them to a small utility. The sample uses the JDK's HttpClient and Jackson, passes the task id back as the JSON node it arrived as (so its type never matters), and stops polling after about two minutes.

import com.fasterxml.jackson.databind.*;
import java.net.URI;
import java.net.http.*;
import java.util.Map;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.support.ui.*;
public class CheckboxFormTest {
    static final String SOLVER_BASE = "https://gatesolver.com";
    static final String KEY = System.getenv().getOrDefault("GATESOLVER_KEY", "YOUR_API_KEY");
    static final HttpClient WIRE = HttpClient.newHttpClient();
    static final ObjectMapper MAPPER = new ObjectMapper();
    static JsonNode call(String route, Map<String, Object> fields) throws Exception {
        var body = new java.util.HashMap<>(fields);
        body.put("clientKey", KEY);
        String json = MAPPER.writeValueAsString(body);
        HttpRequest post = HttpRequest.newBuilder(URI.create(SOLVER_BASE + route))
            .POST(HttpRequest.BodyPublishers.ofString(json)).setHeader("Content-Type", "application/json").build();
        JsonNode reply = MAPPER.readTree(WIRE.send(post, HttpResponse.BodyHandlers.ofString()).body());
        if (reply.path("errorId").asInt() != 0) throw new IllegalStateException(reply.path("errorCode").asText());
        return reply;
    }
    public static void main(String... argv) throws Exception {
        WebDriver chrome = new ChromeDriver();
        chrome.get("https://example.com/register");
        WebElement box = new WebDriverWait(chrome, java.time.Duration.ofSeconds(20)).until(
            ExpectedConditions.presenceOfElementLocated(By.cssSelector(".g-recaptcha[data-sitekey]")));
        JsonNode id = call("/createTask", Map.of("task", Map.of("type", "ReCaptchaV2TaskProxyLess",
            "websiteURL", chrome.getCurrentUrl(), "websiteKey", box.getDomAttribute("data-sitekey")))).get("taskId");
        JsonNode state = null;
        for (int i = 0; i < 40; i++) {
            Thread.sleep(3000);
            state = call("/getTaskResult", Map.of("taskId", id));
            if (!"processing".equals(state.path("status").asText())) break;
        }
        if (state == null || !"ready".equals(state.path("status").asText())) throw new IllegalStateException("no token");
        ((JavascriptExecutor) chrome).executeScript("document.getElementById('g-recaptcha-response').value = arguments[0];",
            state.path("solution").path("gRecaptchaResponse").asText());
        chrome.findElement(By.cssSelector("#register-form [type=submit]")).click();
        chrome.quit();
    }
}

For a Turnstile page, change the selector to .cf-turnstile[data-sitekey], the type to AntiTurnstileTaskProxyLess, read solution.token, and target the input named cf-turnstile-response. In JUnit or TestNG, put the driver in a fixture and the solve in a helper method so every test reads as page actions only.

Waits after the submit

The submit is where most flaky runs hide. Wait for evidence that the server accepted the form: url_changes, staleness_of on the old form element, or the visibility of a success message. If the page instead shows the widget again with an error, the token was refused, and a new solve is the only fix, because each token can be used once. Avoid time.sleep between injection and click; the token starts aging the moment it is issued and reCAPTCHA tokens stop working after about two minutes, as explained in why tokens expire.

Error handling and retries

Split failures into three groups and give each its own reaction. Configuration errors (ERROR_KEY_DENIED_ACCESS, ERROR_ZERO_BALANCE, ERROR_INVALID_TASK_DATA) should stop the run with a clear message, since retrying cannot change the answer. Transient errors (ERROR_SERVICE_UNAVAILABLE, ERROR_RATE_LIMIT) deserve a pause of a few seconds and one or two more attempts. A failed or unsolvable task costs nothing, so one fresh task is reasonable, but reload the page first if the widget may have expired while you waited.

Keep a cap per test or per URL. A suite that solves three times on the same form is telling you something about pacing, IP reputation or browser setup, and the Selenium scraping guide covers the settings that keep challenges rare in the first place.

Scaling with threads and Selenium Grid

GateSolver puts no limit on concurrent tasks, so the solver is rarely the bottleneck; browser sessions are. Run one driver per worker thread or per Grid node, and let each worker solve its own widget in its own session, because a token belongs to the page that requested it. The shared limit to plan for is 600 API requests per minute per key. With a three second poll interval, one solve uses about five to eight requests, which leaves room for dozens of parallel sessions on a single key. On Selenium Grid the code above runs unchanged with webdriver.Remote, since the API calls happen in your test process, not inside the remote browser.

Use this pattern on forms you own, staging copies and public pages whose terms allow automation, such as QA suites, accessibility checks and public data collection.

Common questions

Does this work with headless Chrome in Selenium?

Yes. The token is produced on our side, so the browser mode does not matter for the solve itself; some sites do challenge headless browsers more often, which only changes how often you need a token.

Can Selenium solve reCAPTCHA v3 with the same code?

The structure is the same, but v3 has no checkbox. Use a ReCaptchaV3TaskProxyLess task with the pageAction value and send the token in the request the page makes.

Why is get_dom_attribute used instead of get_attribute?

It reads the attribute exactly as written in the HTML, without the property lookups get_attribute performs. Either works for data-sitekey; the DOM version is simply more predictable.

Is a proxy needed for Selenium tasks?

Usually not. Proxyless types work for most forms; switch to ReCaptchaV2Task with your browser proxy only when a site rejects tokens solved from another IP.

How do I run the Java example with Maven?

Add selenium-java and jackson-databind as dependencies, put the class under src/test/java or src/main/java, and run it with your usual test or exec plugin.

Keep reading