OCR Find Text
OCR Find Text
Section titled “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.
How it works
Section titled “How it works”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 regionx/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, atextwith spaces ("Amount due") is never found: search for the most distinctive word ("due")."Total"does find the wordTotal:. - 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
xandyto get the screen position. - This activity has no preprocessing.
Required parameters
Section titled “Required parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
text | string | — | Text to search for inside a word of the OCR result. |
Optional parameters
Section titled “Optional parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
path | string | — | Path to the image. If set, it is used instead of the screen region. |
x | int | — | Left coordinate of the screen region (px). Required if there is no path. |
y | int | — | Top coordinate of the screen region (px). Required if there is no path. |
width | int | — | Width of the screen region (px). Required if there is no path; greater than zero. |
height | int | — | Height of the screen region (px). Required if there is no path; greater than zero. |
language | string | "eng" | Text language: Tesseract code (eng, spa, eng+spa) or regional tag (es-CO, en-US). See language. |
caseSensitive | bool | false | Match upper and lower case exactly. |
Output
Section titled “Output”Returns an object (dictionary):
| Key | Type | Content |
|---|---|---|
found | bool | true if the text was found. |
x, y | number | Top-left corner of the word found (px). |
width, height | number | Size of the word (px). |
word | string | The full recognized word that contains text. |
line | string | The 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.
Example
Section titled “Example”OCR Find Text x = 200 y = 100 width = 800 height = 150 text = "Export" → output: posIf 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"] + ")"Common errors
Section titled “Common errors”| Message | Cause 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. |
Related activities
Section titled “Related activities”- OCR Recognize File — get all the text instead of a position.
- OCR Get Lines — all lines and words with their coordinates.