Skip to content

OCR Find Text

Type: ocr-find-text  ·  Package: OCR Activities v1.2.5  ·  Output: object

Searches for a text inside an image or screen region and returns its position (coordinates). Useful to locate an element by its label and then, for example, click near it — when there is no other way to find it.

Runs OCR on the source and searches for text word by word:

  • Source: if you set path, it analyzes that image file and the region coordinates are ignored. Otherwise it captures the screen region x/y/width/height (all four are required in that case and need an interactive desktop).
  • Word comparison: it returns the first recognized word that contains text, going through the lines top to bottom. Because it compares against single words, a text with spaces ("Amount due") is never found: search for the most distinctive word ("due"). "Total" does find the word Total:.
  • Case: not case-sensitive by default (caseSensitive = false).
  • Coordinates: in pixels, relative to the analyzed image. With a screen region, they are relative to the region’s corner: add the region’s x and y to get the screen position.
  • This activity has no preprocessing.
ParameterTypeDefaultDescription
textstring—Text to search for inside a word of the OCR result.
ParameterTypeDefaultDescription
pathstring—Path to the image. If set, it is used instead of the screen region.
xint—Left coordinate of the screen region (px). Required if there is no path.
yint—Top coordinate of the screen region (px). Required if there is no path.
widthint—Width of the screen region (px). Required if there is no path; greater than zero.
heightint—Height of the screen region (px). Required if there is no path; greater than zero.
languagestring"eng"Text language: Tesseract code (eng, spa, eng+spa) or regional tag (es-CO, en-US). See language.
caseSensitiveboolfalseMatch upper and lower case exactly.

Returns an object (dictionary):

KeyTypeContent
foundbooltrue if the text was found.
x, ynumberTop-left corner of the word found (px).
width, heightnumberSize of the word (px).
wordstringThe full recognized word that contains text.
linestringThe full line where the word is.

If it is not found, it returns only { "found": false } (without the other keys); it is not an error.

OCR Find Text x = 200 y = 100 width = 800 height = 150 text = "Export" → output: pos
If condition = pos["found"]
└─ then:
Set Variable name = centerX value = 200 + num(pos["x"]) + num(pos["width"]) / 2
Set Variable name = centerY value = 100 + num(pos["y"]) + num(pos["height"]) / 2
Log message = "Button on screen: " + centerX + ", " + centerY + " (line: " + pos["line"] + ")"
MessageCause and fix
'text' is required.text is missing.
File not found.The path does not exist on the robot’s machine.
'path' or screen coordinates 'x', 'y', 'width', 'height' are required.There is no path and no x. Provide one of the two sources.
'y' is required for the screen region. (same for width, height)x was given but another region coordinate is missing.
'width' and 'height' must be greater than zero.The region size is 0 or negative.
Tesseract language '…' not found at '…'. Available: [eng, spa].The language code is not installed.