How to automatically solve reCAPTCHA using Selenium and Auto Captcha Filler

This guide provides a step-by-step approach to bypassing reCAPTCHA using Selenium and an auto-fill method, ideal for developers looking to streamline testing and automation tasks.

reCAPTCHA Auto Bypass Using Selenium and Auto-Fill

In this article, we’ll demonstrate how to bypass image-based reCAPTCHA challenges (3x3 or 4x4 grids) using Selenium and captcha solver.

How to Bypass reCAPTCHA

The reCAPTCHA bypass script operates through several stages:

  1. Detection: The script detects a reCAPTCHA challenge on the webpage.
  2. Capture: It programmatically captures reCAPTCHA image data and relevant parameters.
  3. Sending Data to API: The challenge data is sent to the captcha solver API, which processes the request and returns the correct solution.
  4. Human-Like Interaction: Once the solution is returned, the script interacts with the CAPTCHA widget by clicking specified grid cells, simulating human behavior to reduce detection risk.

Tools:

  • 2Captcha API: Provides high-speed solutions using AI-based image analysis.
  • Selenium WebDriver: Automates browser interaction and handles reCAPTCHA elements.

Installation and Setup

To use this script, clone the repository, install the required dependencies, and run the example script.


# Clone the repository
git clone git@github.com/2captcha/selenium-recaptcha-solver-using-grid.git
cd selenium-recaptcha-solver-using-grid

# Install dependencies
pip install -r requirements.txt

# Run the script
python main.py
            

Configuration

To configure the script, you’ll need to set your 2Captcha API key as an environment variable:


export APIKEY=your_api_key
            

Workflow

This script uses the grid-based method for solving reCAPTCHA challenges. Here’s a breakdown of each step:

  1. Extracting CAPTCHA Data: The script captures challenge image data and relevant parameters for solving the CAPTCHA.
  2. Sending Data to captcha solver API: The captured image data is sent to the captcha solver API, which provides the grid cells to click.
  3. Simulated Interaction: Once the solution is returned, Selenium interacts with the CAPTCHA by clicking the specified cells and finally clicking the `Verify` button to complete the challenge.

Example of a typical API response for a 3x3 grid CAPTCHA:


{
    "rows": 3,
    "columns": 3,
    "type": "GridTask",
    "comment": "Select all images with crosswalks, click verify once none are left",
    "body": "XXXXXXXX"
}
                

Solution response from the API might look like:


{ "status": 1, "data": "click:3/6/8", "id": "XXXXXXXX" }
            

In this response, click:3/6/8 indicates that cells 3, 6, and 8 should be clicked. The grid cells are numbered left to right, top to bottom, starting from the top-left corner.

Typically, solving a reCAPTCHA requires passing 1-5 challenges, though more complex configurations may require additional steps.

Error Handling

  • ERROR_CAPTCHA_UNSOLVABLE: When a CAPTCHA is too complex, implement retry logic or escalation.
  • Temporary Blockage: High failure rates or frequent attempts can trigger temporary reCAPTCHA blocking. Mitigate this with IP rotation or by waiting before retrying.

Pros

  • No Token Management: This method bypasses the need to handle reCAPTCHA tokens directly, relying instead on simulated interactions.
  • Simplified Automation: Direct interactions with reCAPTCHA elements make it an effective solution for automation.

Cons

  • Setup Complexity: Requires time to set up and configure.
  • Variable Costs: Solving CAPTCHAs incurs API costs, which may vary based on difficulty and volume.
  • Browser Automation Dependency: Relies on Selenium, which ensures proper interaction but depends on browser automation.

For JavaScript users, a similar example is available using JavaScript captcha solver with Puppeteer tools.

Final wolds

With this method, you now have a powerful, automated solution for handling reCAPTCHA challenges within your web automation tasks. By combining Selenium with the 2Captcha API, this approach provides a scalable, flexible way to bypass CAPTCHA obstacles seamlessly, allowing you to focus on more important aspects of your workflow. Just remember to handle error scenarios. Happy automating!