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.
The overall workflow looks like this:

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
)
Step 5: Solving reCAPTCHA from Other Languages
The reCAPTCHA call above works from any language. Here are the equivalents:
Node.js
const DBC = require('deathbycaptcha');
const client = new DBC.SocketClient('username', 'password');
const result = await client.decode({
googlekey: 'SITE_KEY',
pageurl: 'https://example.com'
}, 60, 4);
if (result.text) {
await page.evaluate((token) => {
document.getElementById('g-recaptcha-response').innerHTML = token;
}, result.text);
}
PHP
require_once 'deathbycaptcha.php';
$client = new DeathByCaptcha_HttpClient("username", "password");
$token_params = json_encode([
'googlekey' => 'SITE_KEY',
'pageurl' => 'https://example.com',
]);
$captcha = $client->decode(null, ['type' => 4, 'token_params' => $token_params]);
if ($captcha) {
echo "reCAPTCHA token: " . $captcha["text"] . "\n";
}
Java
import com.DeathByCaptcha.Client;
import com.DeathByCaptcha.HttpClient;
import com.DeathByCaptcha.Captcha;
import org.json.JSONObject;
Client client = new HttpClient("username", "password");
JSONObject params = new JSONObject();
params.put("googlekey", "SITE_KEY");
params.put("pageurl", "https://example.com");
Captcha captcha = client.decode(4, params);
if (captcha != null) {
System.out.println("reCAPTCHA token: " + captcha.text);
}
Go
package main
import (
"encoding/json"
"fmt"
"log"
dbc "github.com/deathbycaptcha/deathbycaptcha-api-client-go/v4/deathbycaptcha"
)
func main() {
client := dbc.NewHttpClient("username", "password")
defer client.Close()
tokenParams, _ := json.Marshal(map[string]string{
"googlekey": "SITE_KEY",
"pageurl": "https://example.com",
})
captcha, err := client.Decode(nil, dbc.DefaultTokenTimeout, map[string]string{
"type": "4",
"token_params": string(tokenParams),
})
if err != nil {
log.Fatal(err)
}
if captcha != nil {
fmt.Println("reCAPTCHA token:", *captcha.Text)
}
}
C
using System.Collections;
using DeathByCaptcha;
Client client = new DeathByCaptcha.HttpClient("username", "password");
string tokenParams = "{\"googlekey\":\"SITE_KEY\",\"pageurl\":\"https://example.com\"}";
Captcha captcha = client.Decode(Client.DefaultTimeout,
new Hashtable { { "type", 4 }, { "token_params", tokenParams } });
if (captcha != null)
Console.WriteLine("reCAPTCHA token: " + captcha.Text);
cURL
curl --data-urlencode "username=YOUR_USERNAME" \
--data-urlencode "password=YOUR_PASSWORD" \
--data-urlencode "type=4" \
--data-urlencode 'token_params={"googlekey":"SITE_KEY","pageurl":"https://example.com"}' \
http://api.dbcapi.me/api/captcha
The response is JSON and the reCAPTCHA token arrives in the text field.
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.

English
Spanish
Russian
Chinese
French
Hindi
Arabic
Bengali
Indonesian
Portuguese
com, 