Cookie usage notification

This site uses cookies. Cookies remember you, so we can provide you with personalized services. Read our privacy policy.

Selenium captcha and reCAPTCHA bypass

Bypass reCAPTCHA, hCaptcha, Arkose, Cloudflare Turnstile and any captchas in Selenium with fastest solving service 2Captcha.

No risk. Pay only for solved captchas

Quick Start
Selenium captcha solver in action

Short guide: How to start using 2Captcha anti captcha API in Selenium

  • Sign up for the captcha solving service
  • Add funds and note the API key
  • Note the site key of the target captcha
  • Submit the site key and page URL to 2Captcha to solve
  • Set the solved captcha token on the appropriate element
  • Submit the form
How to Bypass CAPTCHAs With Selenium Automatically, Selenium reCAPTCHA Solver & CAPTCHA bypass
Bypass reCAPTCHA with Selenium

Selenium captcha bypass: How it works

The 2Captcha service is designed to automatically recognize captchas and bypass them.

The bypass process is as follows: using the API, the customer passes a set of necessary parameters from the captcha placement page to the service, where the employee solves it. After that, the customer requests a set of parameters that must be passed to the appropriate fields to solve the captcha on the page.

The captcha recognition service is fully automated.

The API of the service can be used to work with Puppeteer, Selenium, Playwright.

Automate captcha using Selenium

Selenium logo

Selenium automates browsers. That's it! What you do with that power is entirely up to you. Primarily, it is for automating web applications for testing and parsing. There are plugins for Selenium that allow you to hide the fact of automation occurs. Hiding the fact of automation is important when developing parsers, as this will allow the browser to look more like a person and not be exposed.

Bypass captcha with Selenium

To bypass captchas in Selenium, a special bypass service is required.

There is a manual to learn how to use Python Module for interacting with API 2Captcha together with the Selenium library to perform web scraping and testing. You can use multiple programming languages like Java, C#, C++, PHP, Python, and Ruby. Read the bypass instructions for details.

Manual: How to solve captcha in Selenium

The following is a step by step explanation of the reCAPTCHA bypass process at https://recaptcha-demo.appspot.com/recaptcha-v2-checkbox.php:

  • Install the required components
  • Find the site key parameter of the reCAPTCHA on the target webpage
  • Solve the reCAPTCHA using API
  • Submit solved captcha

Installing components

You need to install the following libraries:

  • 2Captcha: Official Python SDK for easy integration with 2Captcha API
  • Selenium
  • webdriver-manager: This library simplifies the download and usage of drivers for Selenium

To install these libraries, run the following command:

python -m pip install 2captcha-python selenium webdriver-manager

Next, you need to find a site key parameter and create a Python file where you write captcha-solving code.

Find site key

The site key is a unique identifier given by Google to all reCAPTCHA an forms, which uniquely identifies the captcha. To solve the captcha, you need to send the site key to the captcha.

To find site key of webpage follow these steps:

Solve the сaptcha

Next, write Selenium code to visit the target page and solve the captcha using 2Captcha.

The following code does just that, remember to replace 2CAPTCHA_API_KEY with your 2Captcha API key and SITE_KEY with the site key you stored earlier.

from selenium.webdriver.common.by import By
from twocaptcha import TwoCaptcha
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver

# Instantiate the WebDriver
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

# Load the target page
captcha_page_url = "https://recaptcha-demo.appspot.com/recaptcha-v2-checkbox.php"
driver.get(captcha_page_url)

# Solve the Captcha
print("Solving Captcha")
solver = TwoCaptcha("2CAPTCHA_API_KEY")
response = solver.recaptcha(sitekey='SITE_KEY', url=captcha_page_url)
code = response['code']
print(f"Successfully solved the Captcha. The solve code is {code}")

In this code, we initialize the TwoCaptcha object with the 2captcha API Key and solve the Captcha by calling the recaptcha method passing in the site key and the current page URL.

The recaptcha method returns a answer containing the solved captcha code which is logged to the console.

Note that The captcha solving process may take some time, so please be patient

Submit solved captcha

Next, we will find the g-recaptcha-response element, set its value to the solved captcha code, and submit the form.

# Set the solved Captcha
recaptcha_response_element = driver.find_element(By.ID, 'g-recaptcha-response')
driver.execute_script(f'arguments[0].value = "{code}";', recaptcha_response_element)

# Submit the form
submit_btn = driver.find_element(By.CSS_SELECTOR, 'button[type="submit"]')
submit_btn.click()

# Pause the execution so you can see the success screen after submission before closing the driver
input("Press enter to continue")
driver.close()

Final code

The following is the final code of the tutorial to solve captcha using API.

from selenium.webdriver.common.by import By
from twocaptcha import TwoCaptcha
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver

# Instantiate the WebDriver
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

# Load the target page
captcha_page_url = "https://recaptcha-demo.appspot.com/recaptcha-v2-checkbox.php"
driver.get(captcha_page_url)

# Solve the Captcha
print("Solving Captcha")
solver = TwoCaptcha("2CAPTCHA_API_KEY")
response = solver.recaptcha(sitekey='SITE_KEY', url=captcha_page_url)
code = response['code']
print(f"Successfully solved the Captcha. The solve code is {code}")

# Set the solved Captcha
recaptcha_response_element = driver.find_element(By.ID, 'g-recaptcha-response')
driver.execute_script(f'arguments[0].value = "{code}";', recaptcha_response_element)

# Submit the form
submit_btn = driver.find_element(By.CSS_SELECTOR, 'button[type="submit"]')
submit_btn.click()

# Pause the execution so you can see the screen after submission before closing the driver
input("Press enter to continue")
driver.close()

Replace 2CAPTCHA_API_KEY, SITE_KEY with their values and run the code, the captcha will be solved and you will see the success screen.

hCaptcha logo

Selenium hCaptcha bypass

hCaptcha blocks with automated tasks. 2Captcha is the hCaptcha solving service. The service allows you to bypass hCaptcha on any web page in Selenium.

The API of the service can be used in Selenium. To bypass hCaptcha in Selenium, you need to integrate a library to interact with the API. Read the API instructions for details.

hCaptcha bypass service
C# logo

C# captcha bypass code examples

Integrate the C# library for automatic captcha solving. The API can be integrated into any script. CSharp package for easy integration with the API of the 2Captcha captcha solving service to bypass reCAPTCHA, hCaptcha, Arkose captcha and solve any other captchas. The API can be used in conjunction with Selenium.

C# captcha solver
Java logo

Java captcha bypass code examples

Integrate a Java library for fast captcha verification bypass. The API can be used in conjunction with Selenium.

Java captcha solver
Ruby logo

Ruby captcha bypass code examples

Integrate a Ruby gem for automatic captcha challenge bypass. The API can be used in conjunction with Selenium.

Ruby captcha solver

Best Selenium anti captcha service

Selenium is a free automated testing framework used to validate web applications across different browsers and platforms. The tool is used by testers and parsers.

You can use the 2Captcha solver extension with Selenium to solve captcha problems. According to CaptchaTheCat analytics, 2Captcha is the best service.

captchathecat
Using 2Captcha solver extension with Selenium to bypass captcha