A runnable Python Selenium Amazon captcha solver: it solves the Amazon captcha ("Type the characters you see in this image") in a real Chrome session using the ImageToText task of the official CapMonster Cloud image captcha solver Python SDK. Use it for QA and automation where you are permitted to work with Amazon pages.
- Opens Amazon in Chrome through Selenium 4; by default the captcha check page
amazon.com/errors/validateCaptcha. - Finds the captcha image and the answer input, trying several selectors for different page layouts.
- Takes a screenshot of the image element and sends it to CapMonster Cloud as an
ImageToTextRequest. - Types the answer, submits the form and repeats if Amazon shows another captcha.
- Python 3.9+
- Google Chrome (Selenium Manager fetches a matching chromedriver)
- A CapMonster Cloud API key (see Get an API key)
git clone https://github.com/CapMonsterCloud/python-selenium-amazon-captcha-solver.git
cd python-selenium-amazon-captcha-solver
pip install -r requirements.txt
export CAPMONSTER_API_KEY=your_key # Windows: set CAPMONSTER_API_KEY=your_key
python examples/solve_amazon_captcha_selenium.py --headed
python examples/solve_amazon_captcha_selenium.py --url https://www.amazon.com/dp/B000000000 --attempts 5Tests (offline):
pytest -q- Element screenshot instead of a second download.
image.screenshot_as_pngcaptures exactly the pixels Chrome shows. Downloading the image URL again could return a different captcha or fail without the browser's cookies. - Selector fallbacks. Amazon serves several versions of the same page.
first_match()walksIMAGE_SELECTORS,INPUT_SELECTORSandSUBMIT_SELECTORSin order and returns the first element found, so one layout change does not stop the script. - Real typing. The answer is entered with
send_keys, which fires the same keyboard events a person would, and the form is submitted with its own button (or Enter if the button is missing). - Answer cleanup and retries.
clean_answer()keeps uppercase Latin letters only, and the loop re-checks the page because Amazon may ask again.
- The task takes a picture of the captcha and returns the recognized characters as text.
- Send only the captcha image itself. The SDK takes the raw image bytes and encodes them for you.
- Each captcha is solved separately: when Amazon shows a new image, take a new screenshot and send a new request.
| Symptom | Cause and fix |
|---|---|
captcha page detected, but the image or input was not found |
Amazon changed the markup. Inspect the page and add the new selector to IMAGE_SELECTORS / INPUT_SELECTORS. |
| Empty or black screenshot in headless mode | The image was not loaded yet. Wait until image.get_attribute("complete") is true or run with --headed. |
captcha is still shown after all attempts |
The session is flagged. Slow down, keep the same profile and cookies, avoid headless for long runs. |
SessionNotCreatedException |
Chrome and chromedriver versions differ. Remove old drivers from PATH and update Selenium. |
[ERROR_ZERO_BALANCE] / [ERROR_KEY_DOES_NOT_EXIST] |
Top up the balance or check the API key. |
This example needs a CapMonster Cloud account and API key. Register and get the key on the image captcha recognition page. There you will also find pricing and the API description. New users can ask support for a $0.10 test balance after registering.
Automated access to Amazon is subject to Amazon's Conditions of Use. Run this example only where you are permitted, for example QA of your own seller workflows, and respect applicable laws. Keep your API key private.
- Python SDK: CapMonster Cloud Python SDK
- Image captcha recognition with CapMonster Cloud: capmonster.cloud/en/image-to-text
Amazon is a trademark of Amazon.com, Inc. or its affiliates. Selenium is a project of the Selenium community. CapMonster Cloud is not affiliated with or endorsed by these companies.