Use a CAPTCHA solver with Selenium
Use solvethree to obtain a reCAPTCHA Enterprise token, then use Selenium to put solution.token into your application's form and submit it. The SDK solves the task; it doesn't fill the browser form for you.
The example uses an HTTPS form with a token field and a submit button. Adapt those selectors to the application you are testing.
On this page
Prepare the form and Python environment
- 1.
Install the dependencies
Use Python 3.10 or newer with Chrome. Install the
seleniumpackage through pip, then install the official solvethree Python SDK from its downloadable wheel. Use the direct-download installation instructions in the Python integration; don't substitute an assumed package-registry installation. - 2.
Configure the target profile
Set up the owned form's hostname in the solvethree console and make sure its profile is active for your workspace. Sending a hostname in a task doesn't create that profile. The sample requests the
loginaction; change it if your application uses a different action. - 3.
Set the environment variables
Set
TARGET_URLto your full HTTPS form URL,SOLVETHREE_PROXYto your HTTP or HTTPS proxy URL, andSOLVETHREE_API_KEYto your workspace API key. Keep the key in the Python process, not in page JavaScript.
Solve first, then start Chrome with the returned identity
This Chrome sample requires an IP-allowlisted proxy with no username or password. It rejects proxy URLs containing credentials and doesn't implement authenticated proxy setup.
The task uses the hostname extracted from TARGET_URL, the login action and one proxy. After solve returns a ready result, Chrome starts with that same proxy and the returned userAgent. Before navigation, the sample also sets the returned secChUa header.
# Install selenium and the official solvethree Python SDK first.
import os
from urllib.parse import urlsplit
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from solvethree import Solvethree
target = os.environ["TARGET_URL"] # Your configured HTTPS form page.
proxy_url = os.environ["SOLVETHREE_PROXY"]
proxy = urlsplit(proxy_url)
if proxy.username or proxy.password:
raise ValueError("This Chrome example requires an IP-allowlisted proxy without URL credentials")
client = Solvethree(os.environ["SOLVETHREE_API_KEY"])
result = client.solve({"site": urlsplit(target).hostname, "action": "login", "proxy": proxy_url})
solution = result["solution"]
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=" + proxy_url)
options.add_argument("--user-agent=" + solution["userAgent"])
driver = webdriver.Chrome(options=options)
try:
driver.execute_cdp_cmd("Network.enable", {})
driver.execute_cdp_cmd("Network.setExtraHTTPHeaders", {
"headers": {"sec-ch-ua": solution["secChUa"]}
})
driver.get(target)
# Adapt the field and button to your application's form contract.
field = WebDriverWait(driver, 20).until(
lambda browser: browser.find_element(By.NAME, "g-recaptcha-response")
)
driver.execute_script("""
arguments[0].value = arguments[1];
arguments[0].dispatchEvent(new Event('input', {bubbles:true}));
""", field, solution["token"])
driver.find_element(By.CSS_SELECTOR, 'button[type="submit"]').click()
# Check your application's success response here.
finally:
driver.quit()Solvethree.solve creates the task once and polls until it's ready or raises. Only then does the browser navigate to the form. The script waits for the token field, assigns solution.token, dispatches an input event and clicks the submit button. Chrome is closed in the finally block.
Replace the demo's form assumptions
TARGET_URLis your application's form page. The task'ssiteis its hostname, not the full URL; reCAPTCHA requests don't use aurlortypefield.loginis the sample action. Replace it with the action used by the application and its configured profile.By.NAMEwithg-recaptcha-responselocates the demo textarea. Use the field or submission parameter your application actually reads. Assigning the value and dispatching an input event is the demo's handoff, not a universal reCAPTCHA callback.button[type="submit"]identifies the demo submit button. Replace it with an unambiguous selector for your form and retain the application's required session, CSRF and callback behavior.
The sample's 20-second explicit wait checks only that the textarea exists. After clicking Submit, add a conditional wait for your application's actual outcome, such as its success state or validation error. Use an overall browser-flow deadline separate from the solver timeout; don't replace state checks with fixed sleeps or casually mix implicit and explicit waits.
Check the failing step before buying another solve
- The solver task fails before Chrome starts.
Inspect the terminal task's errorCode and error. Distinguish a failed task from an HTTP request error.
Try this: Correct the reported input, profile or connectivity problem before retrying. Stop polling a failed task; unchanged invalid inputs won't improve with another request.
- Selenium times out finding the textarea.
Confirm that Chrome reached the intended form and that the page actually contains the demo's named field.
Try this: Replace the demo locator with your application's token handoff and wait for the state that makes it available. A longer timeout won't fix the wrong selector.
- The token is ready, but the application rejects submission.
Inspect the outgoing application request first. Check that it contains solution.token—not the task ID or an old value—and that the action, proxy, browser identity and session match the intended flow.
Try this: Correct the submitted parameter or application requirements before requesting another token. A ready task supplies a solution; the application's response determines whether submission was accepted.
Sources and API reference
Run your first task.
Start with $5 in workspace credit.