Captcha Solver for Selenium

Automatically solve and fill image captchas in your Selenium scripts. FastCaptcha solves in 0.3 seconds — screenshot the captcha, get the answer, fill the field. Full Python and Node.js examples included.

How Captcha Solving Works in Selenium

3 simple steps — from captcha detection to form submission

📸

1. Screenshot the Captcha

Locate the captcha image element with Selenium's find_element() and take a screenshot of just that element.

2. Solve in 0.3 Seconds

POST the image to FastCaptcha's API. AI returns the solved text in 0.3–0.7 seconds — no polling, no waiting.

3. Fill & Submit

Type the solved text into the captcha input field with send_keys() and submit the form. Done.

Selenium Captcha Solver Code Examples

Python Selenium (Basic)

from selenium import webdriver
from selenium.webdriver.common.by import By
import requests

def solve_captcha(image_path, api_key):
    """Solve captcha image via FastCaptcha API."""
    res = requests.post(
        "https://fastcaptcha.org/api/v1/ocr/",
        headers={"X-API-Key": api_key},
        files={"image": open(image_path, "rb")}
    )
    return res.json()["text"]

# Setup Selenium
driver = webdriver.Chrome()
driver.get("https://example.com/login")

# Find and screenshot captcha
captcha_img = driver.find_element(By.ID, "captcha-image")
captcha_img.screenshot("captcha.png")

# Solve (0.3 seconds)
API_KEY = "YOUR_FASTCAPTCHA_KEY"
solution = solve_captcha("captcha.png", API_KEY)

# Fill in captcha field and submit
driver.find_element(By.ID, "captcha-input").send_keys(solution)
driver.find_element(By.ID, "submit-btn").click()

Python Selenium (Production-Ready)

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import requests, time

class SeleniumCaptchaSolver:
    def __init__(self, api_key):
        self.api_key = api_key
        self.endpoint = "https://fastcaptcha.org/api/v1/ocr/"

    def solve(self, driver, captcha_selector, input_selector, retries=2):
        """Find captcha, solve it, fill the input field."""
        wait = WebDriverWait(driver, 10)
        captcha_el = wait.until(EC.visibility_of_element_located(
            (By.CSS_SELECTOR, captcha_selector)
        ))

        for attempt in range(retries + 1):
            captcha_el.screenshot("captcha.png")
            res = requests.post(
                self.endpoint,
                headers={"X-API-Key": self.api_key},
                files={"image": open("captcha.png","rb")},
                timeout=10
            )
            if res.ok:
                solution = res.json()["text"]
                input_el = driver.find_element(
                    By.CSS_SELECTOR, input_selector
                )
                input_el.clear()
                input_el.send_keys(solution)
                return solution
            time.sleep(1)
        raise Exception("Captcha solving failed after retries")

# Usage
solver = SeleniumCaptchaSolver("YOUR_API_KEY")
driver = webdriver.Chrome()
driver.get("https://example.com/login")
solver.solve(driver, "#captcha-img", "#captcha-input")
driver.find_element(By.ID, "submit").click()

Node.js Selenium (selenium-webdriver)

const { Builder, By, until } = require('selenium-webdriver');
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');

async function solveCaptchaSelenium() {
  const driver = await new Builder()
    .forBrowser('chrome').build();

  await driver.get('https://example.com/login');

  // Find captcha image element
  const captchaEl = await driver.wait(
    until.elementLocated(By.id('captcha-image')), 10000
  );

  // Screenshot captcha element
  const img64 = await captchaEl.takeScreenshot();
  fs.writeFileSync('captcha.png', img64, 'base64');
  // Solve with FastCaptcha (0.3s)
  const form = new FormData();
  form.append('image', fs.createReadStream('captcha.png'));

  const { data } = await axios.post(
    'https://fastcaptcha.org/api/v1/ocr/',
    form,
    { headers: {
        'X-API-Key': 'YOUR_KEY',
        ...form.getHeaders()
    }}
  );

  // Fill captcha input and submit
  const input = await driver.findElement(By.id('captcha-input'));
  await input.sendKeys(data.text);
  await driver.findElement(By.id('submit')).click();

  await driver.quit();
}

solveCaptchaSelenium();

Selenium Captcha Solving Tips

Screenshot Only the Captcha Element

Use element.screenshot() instead of full-page screenshots. This gives FastCaptcha a clean, cropped captcha image for best accuracy.

Wait for Element Visibility

Use WebDriverWait to ensure the captcha image is fully loaded before screenshotting. A half-loaded image reduces accuracy.

Retry Logic

Some sites refresh the captcha after a wrong answer. Implement a retry loop that re-screenshots and re-solves if the form submission fails.

Total Time Under 1.5s

Screenshot (~0.3s) + FastCaptcha solve (~0.4s) + fill + click = under 1.5 seconds total. Far better than any human-based service.

Add Captcha Solving to Your Selenium Script

Free API key. 100 credits. Copy-paste ready code above.