Skip to main content
Question

OCR Capture errors

  • February 10, 2026
  • 1 reply
  • 92 views

Using OCR Capture (area) to assure a page has updated properly. I am getting an error: 

This may be due to the following reason: Failed to do OCR - 'Exception occurred while OCR Engine initialization with message Unspecified error '.

To continue, edit the bot and fix the error. Then, try again. If you continue to see this message, please contact your system administrator.

Code: ba.bot.execution.error

I can copy the OCR line out of my bot and use it in a test bot with just that line and the OCR runs without issue. I can also create a new test bot and do an OCR capture on this page/area with no errors. 

What would cause this to fail this way, but run all by itself? 

 

1 reply

Forum|alt.badge.img

Root Causes – In Order of Likelihood

1. Screen / Window Focus Lost Before OCR Capture (Most Common)

The OCR Capture (Area) action requires the target window/screen to be in focus and fully rendered at the moment of capture. Inside a larger bot:

  • A previous action (click, keystroke, database call, file operation) may have shifted focus away from the target window.
  • The window may be partially obscured, minimized, or behind another window.
  • A previous action may have triggered a loading/transition state where the page is not fully rendered when OCR fires.

Fix:

  • Add a Window: Focus or Window: Restore action immediately before the OCR Capture step.
  • Add a Wait/Delay (2–5 seconds) before the OCR action to ensure the page has fully loaded/updated.
  • Use Window: Exists to confirm the target window is active before OCR fires.

2. Race Condition – OCR Fires Before Page Has Fully Updated

Since you are using OCR specifically to verify a page has updated properly, the OCR may be firing before the update is complete:

  • The previous action (submit, save, navigate) triggers a page update.
  • The bot immediately proceeds to the OCR step.
  • The page is still rendering/loading when OCR tries to initialize.
  • The OCR engine fails to capture a stable screen state → "Unspecified error".

Fix:

// Before OCR Capture:
Action: Wait (3–5 seconds)
OR
Action: Wait for Window (wait for the updated page title/element to appear)
OR
Action: Image Recognition: Wait for image to appear (wait for a known
element on the updated page)
THEN
Action: OCR Capture (Area)

3. OCR Engine Resource Exhaustion / Memory Leak in Long-Running Bot

The OCR engine (Tesseract or ABBYY, depending on your AA version) initializes a separate process/engine instance each time it is called. In a larger bot:

  • If the bot has been running for a long time before reaching the OCR step.
  • If there are many previous actions consuming memory (large DataTables, many file operations, multiple browser sessions).
  • The OCR engine may fail to allocate sufficient memory to initialize, resulting in "Unspecified error during initialization."

Fix:

  • Add an explicit Wait before the OCR step to allow system resources to stabilize.
  • Check Task Manager during bot execution to monitor memory usage at the point of OCR failure.
  • If memory is high, consider breaking the bot into smaller child bots called via Run Bot to release memory between phases.

4. Screen Lock / Session State Change

In a larger bot, especially one that runs for extended periods:

  • The Windows session may have locked or gone into a screen saver state before the OCR step.
  • A UAC prompt or system notification may have appeared on top of the target window.
  • A Windows Update notification or background process may have overlaid the screen.

OCR Capture (Area) captures the literal screen pixels — any overlay or lock screen will cause it to fail or capture the wrong content.

Fix:

  • Ensure the Bot Runner session is configured to prevent screen lock during automation.
  • Add Window: Focus on the target application immediately before OCR.
  • Check for and dismiss any system overlays before OCR fires.

5. Previous Action Left a Modal Dialog / Popup Open

A previous step in the larger bot may have triggered a modal dialog, popup, or alert that:

  • Is not visible (hidden behind the main window).
  • Is blocking the OCR engine from accessing the screen properly.
  • Causes the OCR initialization to fail with an unspecified error.

Fix:

  • Add error handling before the OCR step to check for and dismiss unexpected dialogs.
  • Use Window: Close or Keyboard: Press Escape to dismiss any lingering popups before OCR fires.

6. OCR Package / Tesseract Engine Temp File Conflict

The AA OCR engine writes temporary files during initialization (language data files, engine config). In a larger bot:

  • If a previous OCR call in the same bot (or a previous bot run that didn't clean up) left locked temp files.
  • The OCR engine fails to initialize because it cannot write its required temp files.
  • This only manifests in the larger bot if there was a prior OCR call earlier in the same execution.

Check:

  • Look in C:\Users[BotRunner]\AppData\Local\Temp\ for any AA OCR-related temp files.
  • Check if there is another OCR action earlier in the same bot that may not be releasing the engine properly.

Fix:

  • Add a Wait between consecutive OCR calls in the same bot.
  • Ensure OCR actions are not running in parallel threads within the same bot.

7. Capture Area Coordinates Are Off-Screen or Invalid in Context

The OCR Capture (Area) uses fixed screen coordinates recorded at design time. In the larger bot:

  • A previous action may have changed the screen resolution or window size/position.
  • The target application window may have opened at a different position than when the bot was designed.
  • The capture area coordinates may now point to an off-screen or invalid region.

Fix:

  • Use relative coordinates or anchor-based capture rather than absolute screen coordinates.
  • Add a Window: Move/Resize action before OCR to ensure the target window is in the expected position.
  • Verify the capture area is valid by adding a Screenshot action just before OCR to visually confirm what the screen looks like at that point.

Recommended Action Plan

Priority Action
1 Add Wait (3–5 seconds) immediately before the OCR Capture action
2 Add Window: Focus on the target application immediately before OCR
3 Add a Screenshot action just before OCR to visually confirm screen state during debugging
4 Check for modal dialogs/popups that may be open before OCR fires
5 Check Task Manager memory usage at the point of failure
6 Review if there are other OCR calls earlier in the same bot
7 Verify capture area coordinates are still valid in the context of the larger bot
8 Check Bot Agent logs at C:\ProgramData\AutomationAnywhere\BotRunner\Logs\ for detailed OCR error

Debugging Technique: Isolate the Context

To pinpoint exactly what is causing the conflict, use this approach:

// Binary search the larger bot:

Step 1: Run the first HALF of the bot → then run OCR → does it fail?
YES → problem is in first half
NO → problem is in second half

Step 2: Narrow down further until you identify the SPECIFIC action
that, when run before OCR, causes the failure.

Step 3: That action is your root cause.

This will definitively identify which preceding action is corrupting the state that OCR depends on.

Pro Tip: Alternative to OCR for Page Verification

Since you are using OCR specifically to verify a page has updated, consider these more reliable alternatives:

Alternative How
Image Recognition: Find Image Check for a known image/element on the updated page
Recorder/DOMX: Get Property Read a text property from a UI element directly
Window: Get Title Verify the window title has changed to the expected value
Object Cloning: Get Text Extract text directly from UI element without OCR

These approaches are more reliable than OCR for page verification as they don't depend on screen rendering state.

References

  • AA OCR Package Docs: https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/ocr-package.html
  • AA Image Recognition: https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/image-recognition-package.html