An Unsuccessful Attempt to use OCR to Pass text-based Captcha in Selenium Automated Tests

Not recommended, but a fun exercise with using an OCR

Zhimin Zhan

--

A repost of my daughter’s article with permission. I added it here for the convenience of my blog subscribers.

This article is included in my “How to in Selenium WebDriver” series.

First of all, Captchas are designed to stop automation. Ideally, Captchas would be disabled for automated testing, but this is not always possible (out of your control or due to human reasons).

Most Captchas these days are more advanced, they use images and very heavily distorted text. Even so, some sites still use more basic text captchas, like below.

Today, I came up with an idea to attempt OCR (Optical Character Recognition) in automated test scripts to parse the text-based captchas like the above. I give the result first: very low accuracy, i.e. no practical use. However, I think it is a good exercise.

Tesseract OCR library

Tesseract is a popular, free and open-source OCR library, and it runs on multiple platforms. Use the package manager to install it, for example, Homebrew for macOS.

brew install tesseract

--

--