Selenium.AntiCaptcha
2.1.1
dotnet add package Selenium.AntiCaptcha --version 2.1.1
NuGet\Install-Package Selenium.AntiCaptcha -Version 2.1.1
<PackageReference Include="Selenium.AntiCaptcha" Version="2.1.1" />
<PackageVersion Include="Selenium.AntiCaptcha" Version="2.1.1" />
<PackageReference Include="Selenium.AntiCaptcha" />
paket add Selenium.AntiCaptcha --version 2.1.1
#r "nuget: Selenium.AntiCaptcha, 2.1.1"
#addin nuget:?package=Selenium.AntiCaptcha&version=2.1.1
#tool nuget:?package=Selenium.AntiCaptcha&version=2.1.1
Selenium.AntiCaptcha
Selenium.AntiCaptcha
A powerful .NET library that integrates Selenium WebDriver with Anti-Captcha.com's API to automatically solve various types of CAPTCHAs on web pages.
Features
- 🔍 Automatic CAPTCHA detection - Identifies CAPTCHAs on the page without manual configuration
- 🛡️ Multi-CAPTCHA support - Works with ReCaptcha v2/v3, FunCaptcha, GeeTest, Turnstile, and more
- 🔄 Proxy support - Works with or without proxies
- 🚀 Performance optimized - Caches site keys and optimizes requests
- ⚙️ Highly configurable - Customize timeouts, retries, and behavior
- 🧩 Easy integration - Simple extension methods for Selenium WebDriver
Supported CAPTCHA Types
- ReCaptcha v2 (with and without proxy)
- ReCaptcha v2 Enterprise (with and without proxy)
- ReCaptcha v3 (with and without proxy)
- ReCaptcha v3 Enterprise
- FunCaptcha (with and without proxy)
- GeeTest v3/v4 (with and without proxy)
- Image to Text captcha
- Turnstile captcha (with and without proxy)
- Image to Coordinates
Installation
A .NET library designed to seamlessly integrate Anti-Captcha.com services with Selenium WebDriver, enabling automated solving of various captcha types during your web automation tasks.
This library leverages the AntiCaptchaApi.Net
library for communication with the Anti-Captcha API and provides convenient extension methods for IWebDriver
.
Features
Supports a wide range of captcha types, including (but not limited to):
- ReCaptcha V2 (Normal and Invisible)
- ReCaptcha V2 Enterprise
- ReCaptcha V3
- FunCaptcha
- GeeTest (V3 and V4)
- ImageToText
- Turnstile
Installation
- Install via NuGet Package Manager:
This will also installInstall-Package Selenium.AntiCaptcha
AntiCaptchaApi.Net
as a dependency.
Configuration and Usage (Dependency Injection)
This library is designed to be used with .NET's built-in Dependency Injection (DI) system.
1. Register IAnticaptchaClient
In your application's startup code (e.g., Program.cs
for .NET 6+ or Startup.cs
for older .NET Core versions), register the IAnticaptchaClient
service provided by AntiCaptchaApi.Net
:
// Program.cs (.NET 6+)
using AntiCaptchaApi.Net.Extensions; // Required for AddAnticaptcha
var builder = WebApplication.CreateBuilder(args);
// Add other services...
builder.Services.AddAnticaptcha("YOUR_ANTI_CAPTCHA_API_KEY", clientConfig =>
{
// Optional: Configure ClientConfig properties if needed
// clientConfig.MaxHttpRequestTimeMs = 45000;
// clientConfig.DefaultTimeout = TimeSpan.FromSeconds(120);
});
var app = builder.Build();
// ...
Replace "YOUR_ANTI_CAPTCHA_API_KEY"
with your actual API key from Anti-Captcha.com.
2. Inject IAnticaptchaClient
Inject the IAnticaptchaClient
into any service where you need to solve captchas:
using AntiCaptchaApi.Net;
using OpenQA.Selenium;
using Selenium.AntiCaptcha; // Required for IWebDriver extensions
using Selenium.AntiCaptcha.Models;
public class MyAutomatedTaskService
{
private readonly IWebDriver _driver;
private readonly IAnticaptchaClient _anticaptchaClient;
public MyAutomatedTaskService(IWebDriver webDriver, IAnticaptchaClient anticaptchaClient)
{
_driver = webDriver;
_anticaptchaClient = anticaptchaClient;
}
public async Task PerformTaskWithCaptcha()
{
_driver.Navigate().GoToUrl("your_target_website_with_captcha");
// Prepare solver arguments
var solverArgs = new SolverArguments
{
WebsiteUrl = _driver.Url,
// WebsiteKey = "your_recaptcha_site_key", // If known, otherwise it might be auto-detected for some types
// CaptchaType = CaptchaType.ReCaptchaV2, // Specify if known, otherwise auto-detection will be attempted
// ProxyConfig = new ProxyConfig { /* ... if using a proxy for solving ... */ }
};
var actionArgs = new ActionArguments
{
// Specify elements to interact with after solving, if needed
// ResponseElement = _driver.FindElement(By.Id("g-recaptcha-response")),
// SubmitElement = _driver.FindElement(By.Id("submit-button"))
};
try
{
// Call the SolveCaptchaAsync extension method
var solutionResponse = await _driver.SolveCaptchaAsync(_anticaptchaClient, solverArgs, actionArgs);
if (solutionResponse.ErrorId > 0)
{
Console.WriteLine($"Anti-Captcha Error: {solutionResponse.ErrorDescription}");
// Handle error
}
else
{
// For generic response, you might need to cast or check the specific solution type
// if (solutionResponse is TaskResultResponse<RecaptchaSolution> recaptchaSolution)
// {
// Console.WriteLine($"Captcha solved! Token: {recaptchaSolution.Solution.GRecaptchaResponse}");
// }
Console.WriteLine("Captcha solved successfully (details depend on captcha type).");
// Proceed with automated task
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
// Handle exceptions (e.g., UnidentifiableCaptchaException, InsufficientSolverArgumentsException)
}
}
// Example for a specific solution type
public async Task SolveReCaptchaV2Specifically()
{
_driver.Navigate().GoToUrl("your_recaptcha_v2_page");
var solverArgs = new SolverArguments(_driver.Url, "your_recaptcha_site_key", CaptchaType.ReCaptchaV2);
var result = await _driver.SolveCaptchaAsync<AntiCaptchaApi.Net.Models.Solutions.RecaptchaSolution>(_anticaptchaClient, solverArgs);
if (result.ErrorId == 0)
{
Console.WriteLine($"ReCaptcha V2 solved! Token: {result.Solution.GRecaptchaResponse}");
// Use the token (e.g., set it in a hidden field)
}
else
{
Console.WriteLine($"Error solving ReCaptcha V2: {result.ErrorDescription}");
}
}
}
3. Solver Arguments (SolverArguments
)
The SolverArguments
class allows you to provide necessary details for the captcha solving task:
CaptchaType
(optional): Explicitly specify theSelenium.AntiCaptcha.Enums.CaptchaType
. If not provided, the library will attempt to identify it.WebsiteUrl
(often required): The URL of the page where the captcha is present.WebsiteKey
(often required for ReCaptcha, FunCaptcha, etc.): The site key associated with the captcha.ImageElement
(for ImageToText): TheIWebElement
pointing to the captcha image.ImageFilePath
(for ImageToText): Path to a local image file.ProxyConfig
(optional): If the captcha needs to be solved using a specific proxy, configure it here.ProxyType
ProxyAddress
ProxyPort
ProxyLogin
(optional)ProxyPassword
(optional)
- Other captcha-specific parameters (e.g.,
MinScoreForRecaptchaV3
,GeeTestChallenge
,FunCaptchaApiJsSubdomain
).
4. Action Arguments (ActionArguments
)
The ActionArguments
class allows you to specify Selenium elements to interact with after a successful solve:
ResponseElement
: AnIWebElement
(e.g., a textarea) where the captcha solution token should be placed.SubmitElement
: AnIWebElement
(e.g., a submit button) to be clicked after the token is placed.ShouldFindAndFillAccordingResponseElements
: If true, the library will attempt to find common response elements for certain captcha types.ShouldResetCookiesBeforeAdd
: If true, cookies returned by Anti-Captcha (e.g., for AntiGate) will clear existing cookies before being added.
Migration from Older Versions
If you were using a version of this library that accepted a clientKey
string directly in the SolveCaptchaAsync
methods, please see the MIGRATION.md guide for details on updating your code.
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- AntiCaptchaApi.Net (>= 2.1.2)
- Newtonsoft.Json (>= 13.0.3)
- Selenium.FramesSearcher.Extensions (>= 1.8.1)
- Selenium.WebDriver (>= 4.15.0)
-
net9.0
- AntiCaptchaApi.Net (>= 2.1.2)
- Newtonsoft.Json (>= 13.0.3)
- Selenium.FramesSearcher.Extensions (>= 1.8.1)
- Selenium.WebDriver (>= 4.32.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.1.1 | 234 | 5/19/2025 |
2.1.0 | 228 | 5/14/2025 |
2.0.0 | 219 | 5/14/2025 |
1.12.0 | 126 | 5/11/2025 |
1.11.0 | 114 | 2/25/2025 |
1.10.0 | 138 | 12/15/2024 |
1.8.4 | 823 | 2/26/2023 |
1.8.3 | 676 | 2/25/2023 |
1.8.2 | 630 | 2/25/2023 |
1.8.1 | 629 | 2/25/2023 |
1.8.0 | 638 | 2/25/2023 |
1.7.5 | 675 | 2/5/2023 |
1.7.4 | 643 | 2/5/2023 |
1.7.3 | 626 | 2/5/2023 |
1.7.2 | 623 | 2/5/2023 |
1.7.1 | 631 | 2/5/2023 |
1.7.0 | 621 | 2/4/2023 |
1.6.0 | 718 | 1/21/2023 |
1.5.6 | 680 | 1/19/2023 |
1.5.5 | 686 | 1/14/2023 |
1.5.4 | 718 | 1/14/2023 |
1.5.3 | 709 | 1/14/2023 |
1.5.2 | 686 | 1/14/2023 |
1.5.1 | 702 | 1/14/2023 |
1.5.0 | 694 | 1/14/2023 |
1.4.4 | 744 | 1/14/2023 |
1.4.3 | 685 | 1/13/2023 |
1.4.2 | 698 | 1/13/2023 |
1.4.1 | 692 | 1/13/2023 |
1.4.0 | 689 | 1/13/2023 |
1.3.4 | 682 | 1/13/2023 |
1.3.3 | 650 | 1/13/2023 |
1.3.2 | 679 | 1/2/2023 |
1.3.1 | 651 | 12/29/2022 |
1.3.0 | 677 | 12/28/2022 |
1.2.0 | 713 | 12/28/2022 |
1.1.1 | 687 | 12/27/2022 |
1.1.0 | 685 | 12/26/2022 |
1.0.1 | 693 | 12/26/2022 |
1.0.0 | 689 | 12/24/2022 |
2.1.1: AnticaptchaApi.Net dependency updated
2.1.0: Added multi-targeting support for .NET 8.0-9.0, improved error handling, timeout support, and better documentation.
2.0.0: Initial release with support for multiple captcha types.