CAPSOLVER
Blog
How to solve reCaptcha v2 using Selenium [Python] with Capsolver Extension

How to Solve reCAPTCHA V2 Using Selenium [Python] with CapSolver Extension

Logo of CapSolver

Ethan Collins

Pattern Recognition Specialist

26-Mar-2024


In the world of automated testing and data scraping, CAPTCHAs are undoubtedly one of the biggest obstacles. Google's reCaptcha v2, in particular, often proves too complex for many automation tools.

However, with the CapSolver browser extension and the powerful Selenium library, solving this problem becomes straightforward. This article provides a detailed guide on how to integrate the CapSolver extension into your Python Selenium project to achieve automatic recognition and bypass of reCaptcha v2.


Why Choose the CapSolver + Selenium Combination?

Developers often face multiple choices when dealing with CAPTCHAs. Here are the advantages of the CapSolver extension compared to traditional methods:

Feature CapSolver Browser Extension Traditional Image Recognition/ML Solutions Pure API Solutions
Integration Difficulty Extremely Low. Simply load the extension; no need to modify core business logic. Extremely High. Requires extensive data for model training, with high maintenance costs. Medium. Requires manual parsing of website parameters (sitekey, url) and result injection.
Applicable Scope Works for various types, including reCaptcha v2/v3,AWS WAF, Cloudflare Turnstile and challenge and more. Limited to specific CAPTCHA types; poor versatility. Applicable to various types, but requires writing different parsing logic for each type.
Automation Level Fully Automatic. The extension automatically detects and solves the CAPTCHA in the background. Semi-Automatic. Requires additional code for screenshotting, model calling, and result injection. Semi-Automatic. Requires code to fetch parameters, call the CapSolver API, and inject the result.
Anti-Scraping Risk Low. Simulates real user browser behavior, making it less likely to be detected. High. Behavioral patterns can be overly mechanical, easily flagged by anti-scraping mechanisms. Medium. Token injection is relatively secure, but still requires handling browser fingerprinting issues.

The strength of the CapSolver extension lies in its seamless integration and fully automatic solving capability, which greatly simplifies the complexity of handling CAPTCHAs within the Selenium automation workflow.


1. Environment Setup: Install Selenium and Browser Driver

First, ensure that the Selenium library is installed in your Python environment.

bash Copy
pip install selenium

Additionally, you will need to download and configure the appropriate driver (e.g., ChromeDriver for Chrome or GeckoDriver for Firefox) for your chosen browser. Please ensure the driver version is compatible with your browser version.

2. Configuring the CapSolver Browser Extension

The CapSolver extension is the key to achieving automatic decoding.

Step 2.1: Download and Unzip the Extension

Download the latest version of the extension file from the CapSolver GitHub Repository and unzip it into the ./CapSolver.Browser.Extension folder at the root of your project.

Step 2.2: Set the API Key

The core configuration file for the extension is located at ./CapSolver.Browser.Extension/assets/config.json. You need to enter your CapSolver API Key here.

Tip: You can find your API Key on the CapSolver User Dashboard.

json Copy
{
  "apiKey": "Your CapSolver API Key",
  "useCapsolver": true,
  "useProxy": false,
  // ... other configuration items
  "enabledForRecaptcha": true,
  "reCaptchaMode": "token"
  // ...
}

You can adjust other configurations as needed, such as enabling a proxy (useProxy) or changing the reCaptcha solving mode (reCaptchaMode). The CapSolver official documentation provides more detailed configuration instructions; we recommend consulting the CapSolver Developer Settings Guide.

3. Writing the Selenium Automation Code

Now, we will write the Python code to launch Selenium and load the CapSolver extension.

Step 3.1: Loading the Extension

When launching ChromeDriver, we need to load the extension's path using the add_argument method.

python Copy
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def solve_recaptcha_with_capsolver():
    # 1. Get the absolute path of the extension
    # Ensure the path correctly points to your unzipped CapSolver.Browser.Extension folder
    extension_path = os.path.abspath('./CapSolver.Browser.Extension')
    
    # 2. Configure Chrome Options
    chrome_options = Options()
    # Crucial step: Load the CapSolver extension
    chrome_options.add_argument(f'--load-extension={extension_path}')
    
    # 3. Launch WebDriver
    # Ensure your ChromeDriver path is added to the system environment variables
    driver = webdriver.Chrome(options=chrome_options)
    
    # 4. Navigate to the reCaptcha demo page
    # We use the official Google reCaptcha v2 demo page for testing here
    driver.get('https://www.google.com/recaptcha/api2/demo')

    print("Browser launched. CapSolver extension is automatically solving reCaptcha in the background...")

    # 5. Wait for the CAPTCHA to be solved
    # The CapSolver extension automatically solves the CAPTCHA in the background and injects the Token upon success.
    # We can wait for an element on the page that only becomes clickable after the CAPTCHA is solved,
    # such as the submit button here, to confirm the process is complete.
    try:
        # Wait for the submit button to become clickable, which usually means reCaptcha has been solved
        WebDriverWait(driver, 30).until(
            EC.element_to_be_clickable((By.ID, 'recaptcha-demo-submit'))
        )
        print("reCaptcha solved successfully!")
        
        # At this point, you can proceed with subsequent form submission or other automation actions
        # driver.find_element(By.ID, 'recaptcha-demo-submit').click()
        
    except Exception as e:
        print(f"Timeout or error occurred: {e}")
        
    finally:
        # 6. Close the browser
        # driver.quit()
        # To allow you to observe the result, the browser is not closed here; you can close it manually
        print("Please manually close the browser window to end the program.")

if __name__ == "__main__":
    solve_recaptcha_with_capsolver()

Step 3.2: Running the Code

Run the Python script above. When the browser launches and loads the demo page, the CapSolver extension will automatically detect reCaptcha v2 and begin solving it. Once successfully solved, WebDriverWait will pass, and your automation flow can continue with subsequent actions, such as submitting a form.

Frequently Asked Questions (FAQ)

Question Answer
Which browsers does the CapSolver extension support? The CapSolver extension primarily supports Chromium-based browsers (like Chrome, Edge) and Firefox. In Selenium, we typically use ChromeDriver or GeckoDriver to load the extension.
How can I confirm that the CapSolver extension is working correctly? Check if your apiKey in config.json is correct. After the browser launches, you can check the extension's logs or console output to confirm if it successfully detected and solved the CAPTCHA. If successful, the reCaptcha checkbox will show a green checkmark.
What if I want to solve hCaptcha or reCaptcha v3? The CapSolver extension is versatile. You only need to ensure the corresponding configuration items (e.g., enabledForRecaptchaV3 or enabledForhCaptcha) in config.json are set to true, and the extension will handle it automatically. The code logic remains the same.
Can I use the CapSolver API instead of the extension? Absolutely. CapSolver provides a powerful API interface. Using the API requires you to manually parse the website's sitekey and URL, call the API to get the Token, and finally inject the Token into the form via JavaScript. The advantage of the extension is that it handles all these tedious steps for you.

Conclusion

By combining the CapSolver browser extension with Selenium Python, we have successfully cleared the reCaptcha v2 hurdle for automation projects. This method is not only efficient but also significantly reduces the risk of being detected by the target website's anti-scraping mechanisms, due to its nature of simulating real user behavior.

Now, you can focus your energy on more critical automation tasks, leaving the CAPTCHA challenge to CapSolver.

Redeem Your CapSolver Bonus Code

Don’t miss the chance to further optimize your operations! Use the bonus code CAPN when topping up your CapSolver account and receive an extra 5% bonus on each recharge, with no limits. Visit the CapSolver Dashboard to redeem your bonus now!

Compliance Disclaimer: The information provided on this blog is for informational purposes only. CapSolver is committed to compliance with all applicable laws and regulations. The use of the CapSolver network for illegal, fraudulent, or abusive activities is strictly prohibited and will be investigated. Our captcha-solving solutions enhance user experience while ensuring 100% compliance in helping solve captcha difficulties during public data crawling. We encourage responsible use of our services. For more information, please visit our Terms of Service and Privacy Policy.

More

The-Ultimate-CAPTCHA-Solver
Best Captcha Solver Extension, What Extension Service Solves Captcha Automatically?

Solve CAPTCHAs automatically with the CapSolver browser extension — the fastest, AI-powered CAPTCHA solver for Chrome

Extension
Logo of CapSolver

Sora Fujimoto

21-Oct-2025

Captcha Solver Extensions
Captcha Solver Extensions, How to Install Captcha Solver Extension

How to install and use the CapSolver browser extension — the best AI-powered CAPTCHA solver for Chrome and Firefox. Discover its benefits, automation integration, and easy setup guide for effortless CAPTCHA handling.

Extension
Logo of CapSolver

Lucas Mitchell

20-Oct-2025

reCAPTCHA-Auto-Solver
How to Solve reCAPTCHAs Automatically | the Best reCAPTCHA Auto Solver

Discover the ultimate reCAPTCHA Auto Solver. Learn how CapSolver's AI-powered Chrome Extension automates reCAPTCHA v2, v3 solving with high accuracy and efficiency. Boost your productivity today.

Extension
Logo of CapSolver

Ethan Collins

20-Oct-2025

Auto Captcha Solver Chrome
Auto Captcha Solver Chrome: CapSolver Auto Solver Extension Download

Looking for the best Chrome extension to automatically solve captchas? CapSolver Auto Solver Extension offers a fast, AI-powered way to bypass reCAPTCHA and other verification challenges.

Extension
Logo of CapSolver

Lucas Mitchell

18-Oct-2025

Auto CAPTCHA Solver
Auto CAPTCHA Solver, Best CAPTCHA Solver Extension

Learn how to install and use the CapSolver browser extension, the most efficient auto CAPTCHA solver for Chrome, Firefox, Puppeteer, and Selenium. Automate Captcha with AI-powered browser integration.

Extension
Logo of CapSolver

Sora Fujimoto

17-Oct-2025

Auto captcha solver on chrome: CapSolver
What is the Best Auto Captcha Solver on Chrome

CapSolver for Chrome automatically solves CAPTCHAs, saving time and providing a seamless browsing experience.

Extension
Logo of CapSolver

Lucas Mitchell

16-Oct-2025