Home > Language Reference > Wait Functions > Wait for OCR Text

Wait for OCR Text

The Pause until OCR text pauses script execution until the specified text is seen by OCR in the specified window. If after the specified timeout, the pause condition is not met, the block of statements following PauseFalse keyword is executed.

 Video: How to use OCR Text Synchronization


Used to wait for a new frame displayed within the same web page. Use Recording mode or Insert/Synchronization on OCR text menu to generate easily such a Pause.


Pause [x secs] until
    TextOCR(<Text> [,<language>])
 'If the condition is met, the optional statements after the PauseOK and before the PauseFalse are executed
' After the specified timeout, if the condition is not met, the statements after the PauseFalse are executed
     MsgBox("Pause at line "+ #ErrorLine$ +" has failed !",16,"Runtime error")


[x secs], optional. If the pause condition is not met after x seconds, the statements after the PauseFalse keyword are executed. If not specified, the default timeout is the one as defined by #PauseTimeout system variable (default value: 120 seconds). mins can be used instead of secs for a timeout in minutes. As OCR recognition can take a couple of seconds, do not use a too short timeout. 

TextOCR, keyword, specifies the <Text> to OCRize and to wait for. If <language> is specified, the OCR recognition is made using the <language> dictionary (only with MODI OCR engine). Use Insert/Synchronization on OCR Text menu and click Options button to have the list of possible languages.

InWindow, keyword. It specifies the <window_name> and <instance> number of the window where to search the <text>

InArea, optional keyword. It specifies the area as defined by coordinates <x>,<y>,<height>,<width> where to look for the <text>. If not specified, the <text> is searched in the whole <window_name>. For a better OCR recognition, always use InArea.


At execution, a bitmap capture is done for capturing the specified area within the specified window. The captured bitmap is then submitted at the OCR engine which transforms the bitmap in text. Then the text specified in the TextOCR line is compared to the captured and transformed text at execution. If the same text is found, the Pause triggers.

Pause TextOCR compared to Pause Bitmap : both addresses the case where the text displayed within the window cannot be recognized as pure text. We explain here the advantages and drawbacks of each Pause. A pause TextOCR captures the defined area, submits the image to the OCR engine and the Pause triggers if the OCRerized text is seen - then if the text is not seen, the Pause waits around 1 sec before starting again the recognition attempt. So the main drawback of the Pause TextOCR is that it takes a while, the OCR engine can take up to 3-4 secs. There are 3 advantages compared to a Pause bitmap : no extra file for the captured image, a more readable Pause block as the text is seen in the script and the Pause will work even when you distribute the script on other PCs as the bitmap capture is done at execution.
Pause bitmap at execution captures the defined area and compares it to the specified bmp file. If ticks unit is used in the Pause bitmap, as soon as TaskExec sees that it does not trigger, it captures again and compares again, and so on. So with ticks unit, the Pause bitmap can take up to 100% of CPU but will be very fast to execute. If secs unit is used, when the image is not found, the Pause bitmap waits around 1 sec before starting again to capture the defined area. So whatever ticks or secs unit used, a Pause Bitmap will be always faster than a Pause TextOCR. 

See also

Wait for a Date
Wait for Image
Wait for a Keystroke
Wait for a Menu Selection
Wait for a Mouse Click
Wait for a Text
Wait for a Time Delay
Wait for a Window

How to install MODI OCR engine


'Wait until a text typed is there using OCR
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
 SendKeys("Hello Tester")
'Wait until the Tester word is seen using MODI OCR engine
ret = UseOCREngine(1)   'Use MODI engine
Pause 10 secs until
 TextOCR("Tester ")
 InWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
 MsgBox("'Wait for' at line " + #ErrorLine$ + " has failed !")
CloseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
 Click(Button,"Do&n't Save")