Selenium Integration for Authorized CAPTCHA QA
Run a Python REST client alongside Selenium against a controlled fixture. Set the response through your own application test hook.
For authorized QA automation and browser integration. Use only on websites and workflows you have permission to test.
Scope: your own application test hook
This example connects Selenium to an explicit setCaptchaResponseForTest hook in a controlled HTML fixture. It demonstrates passing a response from a server-side REST client into your own test application. It is not a generic mechanism for third-party pages and does not validate a CAPTCHA token.
Verify the fixture first
Download selenium-example.py, its linked client and test-fixture.html into the same directory. Start the local fixture server:
python3 -m http.server 8000 --bind 127.0.0.1
In a second terminal, install the test runner and use a local-only placeholder:
python3 -m pip install selenium
# In another terminal, from the downloaded examples directory:
FIXTURE_TOKEN='local-fixture-only' python3 selenium-example.py
The test fills the hidden response through the fixture's test hook, submits the form and asserts the fixture reports submitted. A browser and its driver must be available in your environment. Keep the fixture and hook confined to your test environment.
Connect a paid task only when needed
Remove FIXTURE_TOKEN and follow the python setup to set your private API Key, stable idempotency key and task JSON. Replace the example site with an authorized test application and configure TEST_PAGE_URL. The test hook must exist in that application. Keep the Key in the runner, never in page scripts.
The fixture itself is not a Turnstile challenge. If the application verifies Turnstile server-side, test that verification separately using its documented flow or official test keys. Client-side fixture submission is not proof of server-side verification.
Match the browser context
For cookie-based tests, use the same proxy/IP and returned useragent before starting the browser context, following the session consistency guide. The downloadable example handles a Turnstile-style response, not every cookie result type. See Turnstile fields and safe polling.
Developer downloads
python-client.py v1.0.0 — standard library only; behaviour and error codes are documented on this page.
Related documentation
Last updated: