|This method is provided by the legacy OCR plugin. In version 12.60, the plugin was replaced with the new Optical Character Recognition plugin powered by Google Cloud Vision API. To learn more, see Optical Character Recognition.
The legacy OCR plugin was removed from TestComplete in version 12.60. If you need to use objects, methods, and properties provided by the legacy plugin with this version of TestComplete, please contact our Customer Care team. The legacy OCR plugin was restored in TestComplete version 14.0. To use the objects, methods, and properties with this or later TestComplete version, you need to install and enable the plugin manually.
OCRObject.GetText method lets you recognize all the text that is available within the visible area of an onscreen object in order to obtain text.
|OCRObjectObj||An expression, variable or parameter that specifies a reference to an OCRObject object|
The method is applied to the following object:
The method has the following parameter:
OCROptions object that includes settings to be used during character recognition.
A string that represents the recognized text.
A number of factors affect the recognition accuracy, read the Using Optical Character Recognition - Tips topic to learn how to improve it.
The following example recognizes the text written in Windows Notepad and posts the obtained text to the test log.
def Main(): p = Sys.Process("notepad") w = p.Window("Notepad", "*").Window("Edit") Rect = w.Picture(0, 0, 200, 25) Log.Picture(Rect, "Region with text to be recognized.") OCRObj = OCR.CreateObject(Rect) OCROptions = OCRObj.CreateOptions() p.Window("Notepad", "*").MainMenu.Click("Format|Font...") w = p.Window("#32770", "Font") Font = OCROptions.Fonts.Add() Font.Name = w.Window("ComboBox", "", 1).wText Font.Sizes.Add(aqConvert.VarToInt(w.Window("ComboBox", "", 3).wText)) w.Window("ComboBox", "", 1).ClickItem("Arial") w.Window("ComboBox", "", 2).ClickItem("Regular") w.Window("Button", "OK").ClickButton() aqUtils.Delay(1000) s = OCRObj.GetText(OCROptions) Log.Message(s, "", pmNormal, None, Rect)