How to Use DeathByCaptcha with Selenium: Step-by-Step Guide
Selenium is the most widely used browser automation framework, and CAPTCHA challenges are one of the most common reasons Selenium scripts break in production. Integrating DeathByCaptcha's selenium captcha solver into your Selenium workflow takes only a few lines of code.
This guide walks through a complete integration using Python and the DBC API.
Prerequisites
- Python 3.7+
- A DeathByCaptcha account (free trial available)
- Selenium installed (
pip install selenium) - A WebDriver for your browser (ChromeDriver, GeckoDriver, etc.)
Step 1: Install the DBC Client
DBC provides an official Python client library:
pip install deathbycaptcha
Step 2: Set Up the DBC Client
import deathbycaptcha
username = "your_username"
password = "your_password"
client = deathbycaptcha.SocketClient(username, password)
client.is_verbose = True
Step 3: Capture and Solve a CAPTCHA
When your Selenium script encounters a CAPTCHA, capture the element and send it to DBC:
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://example.com")
# When a CAPTCHA appears, capture the image
captcha_element = driver.find_element(By.CSS_SELECTOR, "#captcha-image")
captcha_element.screenshot("captcha.png")
# Send to DBC for solving
with open("captcha.png", "rb") as f:
captcha_data = f.read()
captcha_id, solution = client.decode(captcha_data, timeout=60)
if solution:
input_field = driver.find_element(By.CSS_SELECTOR, "#captcha-input")
input_field.send_keys(solution)
submit_button = driver.find_element(By.CSS_SELECTOR, "#submit")
submit_button.click()
Step 4: Handling reCAPTCHA
For reCAPTCHA, use DBC's dedicated endpoint:
captcha_id, solution = client.decode(
{"googlekey": "SITE_KEY", "pageurl": "https://example.com"},
type=4
)
Best Practices
- Reuse the DBC client connection instead of creating a new one for each captcha.
- Set appropriate timeouts (15s for automated solves, 60s for human-assisted).
- Handle errors gracefully with try/except blocks.
- Use DBC's callback mode for high-throughput workflows.

Hindi
English
Spanish
Russian
Chinese
French
Arabic
Bengali
Indonesian
Portuguese
कॉम, 