Use Cases

Automated Login CAPTCHA Handling with CaptchaAI

Login pages are the most common place to encounter CAPTCHAs. Whether it's reCAPTCHA v2, v3, Turnstile, or an image CAPTCHA, CaptchaAI solves the challenge while your automation handles form filling and submission.

Common Login CAPTCHA Types

CAPTCHA How It Appears CaptchaAI Method
reCAPTCHA v2 Checkbox or challenge before submit method=userrecaptcha
reCAPTCHA v3 Invisible scoring, blocks low-score users method=userrecaptcha&version=v3
Cloudflare Turnstile Widget before login form method=turnstile
Image CAPTCHA Text image to type method=base64

Method 1: HTTP Requests (No Browser)

For login forms that accept standard POST requests:

import requests
import time

API_KEY = "YOUR_API_KEY"

def solve_recaptcha(site_key, page_url):
    resp = requests.get("https://ocr.captchaai.com/in.php", params={
        "key": API_KEY, "method": "userrecaptcha",
        "googlekey": site_key, "pageurl": page_url
    })
    task_id = resp.text.split("|")[1]
    for _ in range(60):
        time.sleep(5)
        result = requests.get("https://ocr.captchaai.com/res.php", params={
            "key": API_KEY, "action": "get", "id": task_id
        })
        if result.text == "CAPCHA_NOT_READY": continue
        if result.text.startswith("OK|"): return result.text.split("|")[1]
        raise Exception(result.text)
    raise TimeoutError()

# Login flow
session = requests.Session()
login_url = "https://example.com/login"

# Load login page to get cookies and site key
page = session.get(login_url)
# Extract site_key from the page HTML...
site_key = "6Le-wvkS..."

# Solve CAPTCHA
token = solve_recaptcha(site_key, login_url)

# Submit login form
resp = session.post(login_url, data={
    "username": "user@example.com",
    "password": "your_password",
    "g-recaptcha-response": token
})

if resp.url != login_url:
    print("Login successful!")
    # session now has auth cookies for subsequent requests

Method 2: Selenium (Python)

For login pages that require JavaScript execution:

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
import time

API_KEY = "YOUR_API_KEY"

options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options)

# Navigate to login page
driver.get("https://example.com/login")
wait = WebDriverWait(driver, 10)

# Fill in credentials
username_field = wait.until(EC.presence_of_element_located((By.NAME, "username")))
username_field.send_keys("user@example.com")
driver.find_element(By.NAME, "password").send_keys("your_password")

# Extract site key and solve
recaptcha = driver.find_element(By.CLASS_NAME, "g-recaptcha")
site_key = recaptcha.get_attribute("data-sitekey")

token = solve_recaptcha(site_key, driver.current_url)

# Inject token
driver.execute_script(
    f"document.getElementById('g-recaptcha-response').innerHTML = '{token}';"
)

# Submit
driver.find_element(By.CSS_SELECTOR, 'button[type="submit"]').click()
wait.until(EC.url_changes(driver.current_url))
print(f"Logged in! Now at: {driver.current_url}")

Method 3: Puppeteer (Node.js)

const puppeteer = require("puppeteer");
const axios = require("axios");

const API_KEY = "YOUR_API_KEY";

async function solveRecaptcha(siteKey, pageUrl) {
  const submit = await axios.get("https://ocr.captchaai.com/in.php", {
    params: {
      key: API_KEY,
      method: "userrecaptcha",
      googlekey: siteKey,
      pageurl: pageUrl,
    },
  });
  const taskId = submit.data.split("|")[1];

  while (true) {
    await new Promise((r) => setTimeout(r, 5000));
    const result = await axios.get("https://ocr.captchaai.com/res.php", {
      params: { key: API_KEY, action: "get", id: taskId },
    });
    if (result.data === "CAPCHA_NOT_READY") continue;
    if (result.data.startsWith("OK|")) return result.data.split("|")[1];
    throw new Error(result.data);
  }
}

(async () => {
  const browser = await puppeteer.launch({ headless: "new" });
  const page = await browser.newPage();
  await page.goto("https://example.com/login");

  // Fill credentials
  await page.type("#username", "user@example.com");
  await page.type("#password", "your_password");

  // Get site key and solve
  const siteKey = await page.$eval(".g-recaptcha", (el) =>
    el.getAttribute("data-sitekey")
  );
  const token = await solveRecaptcha(siteKey, page.url());

  // Inject and submit
  await page.evaluate(
    (t) => (document.getElementById("g-recaptcha-response").innerHTML = t),
    token
  );
  await page.click('button[type="submit"]');
  await page.waitForNavigation();

  console.log("Logged in:", page.url());
  await browser.close();
})();

Handling Multi-Factor + CAPTCHA

Some sites combine CAPTCHAs with multi-factor authentication:

# Step 1: Solve CAPTCHA and submit login
token = solve_recaptcha(site_key, login_url)
resp = session.post(login_url, data={
    "username": "user@example.com",
    "password": "your_password",
    "g-recaptcha-response": token
})

# Step 2: Handle MFA page (if redirected)
if "verify" in resp.url or "mfa" in resp.url:
    # Your MFA code logic here
    mfa_code = get_mfa_code()
    resp = session.post(resp.url, data={"code": mfa_code})

# Step 3: Verify logged in
assert "dashboard" in resp.url

Troubleshooting

Issue Cause Fix
Login returns to CAPTCHA page Token expired Solve and submit within 60 seconds
"Invalid credentials" with correct password CSRF token missing Extract and include CSRF token from login page
Session lost after login Cookies not persisted Use requests.Session() or browser cookies
reCAPTCHA v3 blocks despite token Score too low CaptchaAI optimizes for high scores; verify action parameter

FAQ

Can I automate logins to any website?

CaptchaAI handles the CAPTCHA component. Your automation needs to handle the login form itself (filling fields, submitting, managing cookies). The legality depends on your authorization to access the account.

Do I need a browser for login automation?

Not always. Many login pages accept standard HTTP POST requests. Use a browser only when the login requires JavaScript execution or complex interactions.

How do I handle session maintenance after login?

Use requests.Session() in Python or maintain cookies in your browser instance. The session cookies from login are needed for all subsequent authenticated requests.

Discussions (0)

No comments yet.

Related Posts

Reference CAPTCHA Token Injection Methods Reference
Complete reference for injecting solved CAPTCHA tokens into web pages.

Complete reference for injecting solved CAPTCHA tokens into web pages. Covers re CAPTCHA, Turnstile, and Cloud...

Automation Python reCAPTCHA v2
Apr 08, 2026
Comparisons WebDriver vs Chrome DevTools Protocol for CAPTCHA Automation
Compare Web Driver and Chrome Dev Tools Protocol (CDP) for CAPTCHA automation — detection, performance, capabilities, and when to use each with Captcha AI.

Compare Web Driver and Chrome Dev Tools Protocol (CDP) for CAPTCHA automation — detection, performance, capabi...

Automation Python reCAPTCHA v2
Mar 27, 2026
Tutorials CAPTCHA Handling in Flask Applications with CaptchaAI
Integrate Captcha AI into Flask applications for automated CAPTCHA solving.

Integrate Captcha AI into Flask applications for automated CAPTCHA solving. Includes service class, API endpoi...

Automation Cloudflare Turnstile
Mar 17, 2026
Tutorials Pytest Fixtures for CaptchaAI API Testing
Build reusable pytest fixtures to test CAPTCHA-solving workflows with Captcha AI.

Build reusable pytest fixtures to test CAPTCHA-solving workflows with Captcha AI. Covers mocking, live integra...

Automation Python reCAPTCHA v2
Apr 08, 2026
Tutorials CAPTCHA Solving Fallback Chains
Implement fallback chains for CAPTCHA solving with Captcha AI.

Implement fallback chains for CAPTCHA solving with Captcha AI. Cascade through solver methods, proxy pools, an...

Automation Python reCAPTCHA v2
Apr 06, 2026
Use Cases Multi-Step Workflow Automation with CaptchaAI
Manage workflows across multiple accounts on CAPTCHA-protected platforms — , action, and data collection at scale.

Manage workflows across multiple accounts on CAPTCHA-protected platforms — , action, and data collection at sc...

Automation Python reCAPTCHA v2
Apr 06, 2026
API Tutorials Solving CAPTCHAs with Kotlin and CaptchaAI API
Complete guide to solving re CAPTCHA, Turnstile, and image CAPTCHAs in Kotlin using Captcha AI's HTTP API with Ok Http, Ktor client, and coroutines.

Complete guide to solving re CAPTCHA, Turnstile, and image CAPTCHAs in Kotlin using Captcha AI's HTTP API with...

Automation reCAPTCHA v2 Cloudflare Turnstile
Mar 06, 2026
Integrations Puppeteer Stealth + CaptchaAI: Reliable Browser Automation
Standard Puppeteer gets detected immediately by anti-bot systems.

Standard Puppeteer gets detected immediately by anti-bot systems. `puppeteer-extra-plugin-stealth` patches the...

Automation reCAPTCHA v2 Cloudflare Turnstile
Apr 05, 2026
Troubleshooting ERROR_PAGEURL: URL Mismatch Troubleshooting Guide
Fix ERROR_PAGEURL when using Captcha AI.

Fix ERROR_PAGEURL when using Captcha AI. Diagnose URL mismatch issues, handle redirects, SPAs, and dynamic URL...

Automation Python reCAPTCHA v2
Mar 23, 2026
Use Cases Retail Site Data Collection with CAPTCHA Handling
Amazon uses image CAPTCHAs to block automated access.

Amazon uses image CAPTCHAs to block automated access. When you hit their anti-bot threshold, you'll see a page...

Web Scraping Image OCR
Apr 07, 2026
Use Cases Academic Research Web Scraping with CAPTCHA Solving
How researchers can collect data from academic databases, journals, and citation sources protected by CAPTCHAs using Captcha AI.

How researchers can collect data from academic databases, journals, and citation sources protected by CAPTCHAs...

Python reCAPTCHA v2 Cloudflare Turnstile
Apr 06, 2026
Use Cases Cyrillic Text CAPTCHA Solving with CaptchaAI
Solve Cyrillic text CAPTCHAs on Russian, Ukrainian, and other Slavic-language websites — handle character recognition, confusable glyphs, and encoding for Cyril...

Solve Cyrillic text CAPTCHAs on Russian, Ukrainian, and other Slavic-language websites — handle character reco...

Python Image OCR
Mar 28, 2026