Multilogin Alternat
페이지 정보
작성자 omo-serviceraw 조회 1회 작성일 26-08-27 15:19본문
CAPTCHA Solver for Playwright & Selenium Tests: 2026 Guide
If your end-to-end tests touch login, signup, checkout or any protected flow, you have hit the wall: the test runs, the form fills, and then a CAPTCHA stops everything. This guide shows the clean, legitimate way to handle CAPTCHA in Playwright and Selenium suites using a captcha solver API - solve it out-of-band with a service like OMOCaptcha and inject the token, instead of trying to click checkboxes like a human.
Why you should not click CAPTCHAs in tests
- Flaky by design. Interactive challenges are built to detect automation; fighting them makes suites brittle.
- Slow. Every challenge adds seconds of waiting; multiplied by hundreds of runs it destroys feedback time.
- Against the spirit of testing. You are testing your application, not the CAPTCHA vendor.
The professional pattern is token injection: ask a solving API for a token, then set it in the page exactly as the widget would.
The three-step pattern with OMOCaptcha
1. Create a task. Send the page URL and the widget sitekey to https://api.omocaptcha.com/v2/createTask (task type RecaptchaV2TokenTask for reCAPTCHA v2, HCaptchaTokenTask for hCaptcha, TurnstileTokenTask for Turnstile).
2. Poll getTaskResult until status is ready; read the token from solution.
3. Inject the token into the hidden response field and submit the form.
This pattern works because these widgets do not actually check how the token was produced - the target application checks only that the token is valid, unexpired, and matches the sitekey it issued to the page. That is exactly the data your solve request returns, so submitting a solved token is functionally identical, from the server's perspective, to a real user completing the challenge.
Playwright example (reCAPTCHA v2)
import time
import requests
from playwright.async_api import async_playwright
API_KEY = "YOUR_API_KEY"
BASE = "https://api.omocaptcha.com/v2"
def solve_recaptcha(page_url, sitekey):
task = dict(type="RecaptchaV2TokenTask", websiteURL=page_url, websiteKey=sitekey)
create = requests.post(BASE + "/createTask", json=dict(clientKey=API_KEY, task=task)).json()
assert create<>errorId"] == 0
task_id = create<>taskId"]
while True:
res = requests.post(BASE + "/getTaskResult", json=dict(clientKey=API_KEY, taskId=task_id)).json()
if res<>status"] == "ready":
return res<>solution"]<>gRecaptchaResponse"]
assert res<>status"] != "fail"
time.sleep(2)
async def login_with_solved_captcha():
token = solve_recaptcha("https://your-app.example/login", "6Lc_SITEKEY")
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
await page.goto("https://your-app.example/login")
await page.fill("#email", "test-user@example.com")
await page.fill("#password", "secret")
# wait for the widget to render its hidden field, then inject the solved token
await page.wait_for_selector('textarea<name>"g-recaptcha-response"]', state="attached")
await page.eval_on_selector('textarea<name>"g-recaptcha-response"]', "(el, t) => el.value = t", token)
await page.click("button<type>submit]")
await page.wait_for_selector(".dashboard")
Selenium version (same idea)
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://your-app.example/login")
token = solve_recaptcha(driver.current_url, "6Lc_SITEKEY")
field = driver.find_element(By.CSS_SELECTOR, 'textarea<name>"g-recaptcha-response"]')
driver.execute_script("arguments<>].value = arguments<>];", field, token)
driver.find_element(By.CSS_SELECTOR, "button<type>submit]").click()
hCaptcha works identically: the field name is h-captcha-response, and the token comes from solution.gRecaptchaResponse of an HCaptchaTokenTask. Full details in how to solve hCaptcha (https://blog.omocaptcha.com/how-to-solve-hcaptcha).
Test-environment best practices
- Use a dedicated test account and your own application's flows. Solving CAPTCHAs is for testing systems you own or are authorized to test - never for abusing third-party sites.
- Cache tokens briefly. Solved tokens are typically only valid for a couple of minutes, so request them just before submit, not at suite start.
- Keep one user-agent. Use the same UA for solving and for the browser; mismatches look suspicious to validators.
- Budget for latency. Solves average 0.42s on OMOCaptcha (AI-only, no human queue), so a solve per run is affordable even in large suites.
- Watch your spend. Pricing starts from $0.27/1000 for reCAPTCHA-class solves; a 500-run suite costs pennies. See captcha solver API pricing (https://blog.omocaptcha.com/captcha-solver-api-pricing).
- Isolate CI credentials. Use an API key scoped to your test environment so a runaway suite or a misconfigured retry loop cannot burn through your production budget.
When the widget is invisible: reCAPTCHA v3
v3 returns a score instead of a challenge, and low scores silently block real users and tests alike. The fix is the same token-injection pattern with a freshly solved v3 token; see the dedicated reCAPTCHA v3 guide (https://blog.omocaptcha.com/how-to-solve-recaptcha).
Why OMOCaptcha for CI
- Predictable p99: AI-only means no human-queue tail latency wrecking suite duration
- 6 official SDKs (Python, JS/Node, PHP, Java, .NET, Go) match whatever your harness uses
- Refund SLA: full refund if success rate drops below 95%, so a bad day does not become a bill
- 1000 free solves on signup - enough to wire the pattern into your suite before paying anything
FAQ
Does token injection work the same way in Playwright and Selenium?
Yes. Both frameworks expose a way to run arbitrary JavaScript against the page - page.evaluate() in Playwright, execute_script() in Selenium - and that is all token injection needs. Solve captcha challenges out-of-band with the API call shown above, then use whichever JS-execution method your framework provides to write the token into the widget's hidden field before you submit the form.
Will injecting a token get my test account flagged as a bot?
Not if you keep the request path realistic. The token itself comes from a real solve against the real sitekey and page URL, so it validates normally. What can raise flags is everything around it: a mismatched user-agent between the solving request and the browser, a stale token used minutes late, or a test IP with a bad reputation. Match the user-agent, request the token right before submit, and run from infrastructure your own application already trusts.
How much does solving captchas in a test suite actually cost?
Very little for typical suite sizes. reCAPTCHA-class solves start from $0.27 per 1000, so a 500-run nightly suite costs a few cents to a few dollars a month depending on captcha type, and the 1000 free solves on signup cover initial wiring and benchmarking before you spend anything. See captcha solver API pricing (https://blog.omocaptcha.com/captcha-solver-api-pricing) for the full per-type breakdown.
Get the quickstart (https://blog.omocaptcha.com/captcha-solver-api-quickstart), create your key at https://omocaptcha.com (https://omocaptcha.com/en?utm_source=blog&utm_medium=organic), and your next green build will not care which widget your product team shipped. Questions: support@omocaptcha.com, 24/7.
If your end-to-end tests touch login, signup, checkout or any protected flow, you have hit the wall: the test runs, the form fills, and then a CAPTCHA stops everything. This guide shows the clean, legitimate way to handle CAPTCHA in Playwright and Selenium suites using a captcha solver API - solve it out-of-band with a service like OMOCaptcha and inject the token, instead of trying to click checkboxes like a human.
Why you should not click CAPTCHAs in tests
- Flaky by design. Interactive challenges are built to detect automation; fighting them makes suites brittle.
- Slow. Every challenge adds seconds of waiting; multiplied by hundreds of runs it destroys feedback time.
- Against the spirit of testing. You are testing your application, not the CAPTCHA vendor.
The professional pattern is token injection: ask a solving API for a token, then set it in the page exactly as the widget would.
The three-step pattern with OMOCaptcha
1. Create a task. Send the page URL and the widget sitekey to https://api.omocaptcha.com/v2/createTask (task type RecaptchaV2TokenTask for reCAPTCHA v2, HCaptchaTokenTask for hCaptcha, TurnstileTokenTask for Turnstile).
2. Poll getTaskResult until status is ready; read the token from solution.
3. Inject the token into the hidden response field and submit the form.
This pattern works because these widgets do not actually check how the token was produced - the target application checks only that the token is valid, unexpired, and matches the sitekey it issued to the page. That is exactly the data your solve request returns, so submitting a solved token is functionally identical, from the server's perspective, to a real user completing the challenge.
Playwright example (reCAPTCHA v2)
import time
import requests
from playwright.async_api import async_playwright
API_KEY = "YOUR_API_KEY"
BASE = "https://api.omocaptcha.com/v2"
def solve_recaptcha(page_url, sitekey):
task = dict(type="RecaptchaV2TokenTask", websiteURL=page_url, websiteKey=sitekey)
create = requests.post(BASE + "/createTask", json=dict(clientKey=API_KEY, task=task)).json()
assert create<>errorId"] == 0
task_id = create<>taskId"]
while True:
res = requests.post(BASE + "/getTaskResult", json=dict(clientKey=API_KEY, taskId=task_id)).json()
if res<>status"] == "ready":
return res<>solution"]<>gRecaptchaResponse"]
assert res<>status"] != "fail"
time.sleep(2)
async def login_with_solved_captcha():
token = solve_recaptcha("https://your-app.example/login", "6Lc_SITEKEY")
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
await page.goto("https://your-app.example/login")
await page.fill("#email", "test-user@example.com")
await page.fill("#password", "secret")
# wait for the widget to render its hidden field, then inject the solved token
await page.wait_for_selector('textarea<name>"g-recaptcha-response"]', state="attached")
await page.eval_on_selector('textarea<name>"g-recaptcha-response"]', "(el, t) => el.value = t", token)
await page.click("button<type>submit]")
await page.wait_for_selector(".dashboard")
Selenium version (same idea)
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://your-app.example/login")
token = solve_recaptcha(driver.current_url, "6Lc_SITEKEY")
field = driver.find_element(By.CSS_SELECTOR, 'textarea<name>"g-recaptcha-response"]')
driver.execute_script("arguments<>].value = arguments<>];", field, token)
driver.find_element(By.CSS_SELECTOR, "button<type>submit]").click()
hCaptcha works identically: the field name is h-captcha-response, and the token comes from solution.gRecaptchaResponse of an HCaptchaTokenTask. Full details in how to solve hCaptcha (https://blog.omocaptcha.com/how-to-solve-hcaptcha).
Test-environment best practices
- Use a dedicated test account and your own application's flows. Solving CAPTCHAs is for testing systems you own or are authorized to test - never for abusing third-party sites.
- Cache tokens briefly. Solved tokens are typically only valid for a couple of minutes, so request them just before submit, not at suite start.
- Keep one user-agent. Use the same UA for solving and for the browser; mismatches look suspicious to validators.
- Budget for latency. Solves average 0.42s on OMOCaptcha (AI-only, no human queue), so a solve per run is affordable even in large suites.
- Watch your spend. Pricing starts from $0.27/1000 for reCAPTCHA-class solves; a 500-run suite costs pennies. See captcha solver API pricing (https://blog.omocaptcha.com/captcha-solver-api-pricing).
- Isolate CI credentials. Use an API key scoped to your test environment so a runaway suite or a misconfigured retry loop cannot burn through your production budget.
When the widget is invisible: reCAPTCHA v3
v3 returns a score instead of a challenge, and low scores silently block real users and tests alike. The fix is the same token-injection pattern with a freshly solved v3 token; see the dedicated reCAPTCHA v3 guide (https://blog.omocaptcha.com/how-to-solve-recaptcha).
Why OMOCaptcha for CI
- Predictable p99: AI-only means no human-queue tail latency wrecking suite duration
- 6 official SDKs (Python, JS/Node, PHP, Java, .NET, Go) match whatever your harness uses
- Refund SLA: full refund if success rate drops below 95%, so a bad day does not become a bill
- 1000 free solves on signup - enough to wire the pattern into your suite before paying anything
FAQ
Does token injection work the same way in Playwright and Selenium?
Yes. Both frameworks expose a way to run arbitrary JavaScript against the page - page.evaluate() in Playwright, execute_script() in Selenium - and that is all token injection needs. Solve captcha challenges out-of-band with the API call shown above, then use whichever JS-execution method your framework provides to write the token into the widget's hidden field before you submit the form.
Will injecting a token get my test account flagged as a bot?
Not if you keep the request path realistic. The token itself comes from a real solve against the real sitekey and page URL, so it validates normally. What can raise flags is everything around it: a mismatched user-agent between the solving request and the browser, a stale token used minutes late, or a test IP with a bad reputation. Match the user-agent, request the token right before submit, and run from infrastructure your own application already trusts.
How much does solving captchas in a test suite actually cost?
Very little for typical suite sizes. reCAPTCHA-class solves start from $0.27 per 1000, so a 500-run nightly suite costs a few cents to a few dollars a month depending on captcha type, and the 1000 free solves on signup cover initial wiring and benchmarking before you spend anything. See captcha solver API pricing (https://blog.omocaptcha.com/captcha-solver-api-pricing) for the full per-type breakdown.
Get the quickstart (https://blog.omocaptcha.com/captcha-solver-api-quickstart), create your key at https://omocaptcha.com (https://omocaptcha.com/en?utm_source=blog&utm_medium=organic), and your next green build will not care which widget your product team shipped. Questions: support@omocaptcha.com, 24/7.
관련링크
- https://omobrowser.com 0회 연결
- https://omobrowser.com 0회 연결