ExactSearch Property

Applies to TestComplete 15.45, last modified on December 01, 2022
This property 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.

Description

The OCROptions.ExactSearch property lets you specify whether the OCRObject.FindRectByText method should search for the exact match of the given string or for a string that "resembles" the given string. The amount of string similarity is controlled by the OCROptions.SearchAccuracy property. To learn more about character recognition in TestComplete, see Optical Character Recognition.

Declaration

OCROptionsObj.ExactSearch

Read-Write Property Boolean
OCROptionsObj An expression, variable or parameter that specifies a reference to an OCROptions object

Applies To

The property is applied to the following object:

Property Value

True if the exact match of the string is searched. False if a similar string is searched. The default value is True.

Example

The following example uses the OCROptions object to specify that the OCRobject.FindRectByText method will not use the exact search and sets the search accuracy to 0.3. After that, it searches for the "Test" string within the text written in Windows Notepad using the specified OCR options. The rectangle containing the found text is posted to the test log.

JavaScript, JScript

function OCROptionsSample()
{
  var notepad, Window, Rect, OCRObj, OCROptions, RectResult;
  // Obtains the Notepad window
  notepad = Sys.Process("notepad");
  Window = notepad.Window("Notepad", "*").Window("Edit");

  // Captures an image of the Notepad window
  Rect = Window.Picture();
  Log.Picture(Rect, "Region with the text to be recognized");

  // Creates an OCR object
  OCRObj = OCR.CreateObject(Rect);

  // Creates an OCROptions object
  OCROptions = OCRObj.CreateOptions();

  // Specifies that the FindRectByText method will not search for exact matches
  OCROptions.ExactSearch = false;

  // Specifies the comparison accuracy
  OCROptions.SearchAccuracy = 0.3;

  // Searches for the rectangle that contains the "Test" string
  var FindResult = OCRObj.FindRectByText("Test", OCROptions);
  if (FindResult)
  {
    // Obtains the coordinates and the size of the found rectangle
    X = OCRObj.FoundLeft;
    Y = OCRObj.FoundTop;
    dX = OCRObj.FoundWidth;
    dY = OCRObj.FoundHeight;

    RectResult = Window.Picture(X, Y, dX, dY);
    // Posts the found rectangle to the test log
    Log.Picture(RectResult, "Region with the found text:");
  }
}

Python

def OCROptionsSample():
  # Obtains the Notepad window
  notepad = Sys.Process("notepad")
  Window = notepad.Window("Notepad", "*").Window("Edit")
  # Captures an image of the Notepad window
  Rect = Window.Picture()
  Log.Picture(Rect, "Region with the text to be recognized")
  # Creates an OCR object
  OCRObj = OCR.CreateObject(Rect)
  # Creates an OCROptions object
  OCROptions = OCRObj.CreateOptions()
  # Specifies that the FindRectByText method will not search for exact matches
  OCROptions.ExactSearch = False
  # Specifies the comparison accuracy
  OCROptions.SearchAccuracy = 0.3
  # Searches for the rectangle that contains the "Test" string
  FindResult = OCRObj.FindRectByText("Test", OCROptions)
  if FindResult:
    # Obtains the coordinates and the size of the found rectangle
    X = OCRObj.FoundLeft
    Y = OCRObj.FoundTop
    dX = OCRObj.FoundWidth
    dY = OCRObj.FoundHeight
    RectResult = Window.Picture(X, Y, dX, dY)
    # Posts the found rectangle to the test log
    Log.Picture(RectResult, "Region with the found text:")

VBScript

Sub OCROptionsSample

  ' Obtains the Notepad window
  Set notepad = Sys.Process("notepad")
  Set Window = notepad.Window("Notepad", "*").Window("Edit")

  ' Captures an image of the Notepad window
  Set Rect = Window.Picture
  Call Log.Picture(Rect, "Region with the text to be recognized")

  ' Creates an OCR object
  Set OCRObj = OCR.CreateObject(Rect)

  ' Creates an OCROptions object
  Set OCROptions = OCRObj.CreateOptions

  ' Specifies that the FindRectByText method will not search for exact matches
  OCROptions.ExactSearch = False

  ' Specifies the comparison accuracy
  OCROptions.SearchAccuracy = 0.3

  ' Searches for the rectangle that contains the "Test" string
  FindResult = OCRObj.FindRectByText("Test", OCROptions)
  If FindResult Then
    ' Obtains the coordinates and the size of the found rectangle
    X = OCRObj.FoundLeft
    Y = OCRObj.FoundTop
    dX = OCRObj.FoundWidth
    dY = OCRObj.FoundHeight

    Set RectResult = Window.Picture(X, Y, dX, dY)
    ' Posts the found rectangle to the test log
    Call Log.Picture(RectResult, "Region with the found text:")
  End If

End Sub

DelphiScript

procedure OCROptionsSample();
var
  notepad, Window, Rect, OCRObj, OCROptions, RectResult : OleVariant;
  FindResult : boolean;
  X, Y, dX, dY : integer;
begin
  // Obtains the Notepad window
  notepad := Sys.Process('notepad');
  Window := notepad.Window('Notepad', '*').Window('Edit');

  // Captures an image of the Notepad window
  Rect := Window.Picture;
  Log.Picture(Rect, 'Region with the text to be recognized');

  // Creates an OCR object
  OCRObj := OCR.CreateObject(Rect);

  // Creates an OCROptions object
  OCROptions := OCRObj.CreateOptions;

  // Specifies that the FindRectByText method will not search for exact matches
  OCROptions.ExactSearch := false;

  // Specifies the comparison accuracy
  OCROptions.SearchAccuracy := 0.3;

  // Searches for the rectangle that contains the "Test" string
  FindResult := OCRObj.FindRectByText('Test', OCROptions);
  if FindResult then
  begin
    // Obtains the coordinates and the size of the found rectangle
    X := OCRObj.FoundLeft;
    Y := OCRObj.FoundTop;
    dX := OCRObj.FoundWidth;
    dY := OCRObj.FoundHeight;

    RectResult := Window.Picture(X, Y, dX, dY);
    // Posts the found rectangle to the test log
    Log.Picture(RectResult, 'Region with the found text:');
  end;
end;

C++Script, C#Script

function OCROptionsSample()
{
  var notepad, Window, Rect, OCRObj, OCROptions, RectResult;
  // Obtains the Notepad window
  notepad = Sys["Process"]("notepad")
  Window = notepad["Window"]("Notepad", "*")["Window"]("Edit");

  // Captures an image of the Notepad window
  Rect = Window["Picture"]();
  Log.Picture(Rect, "Region with the text to be recognized")

  // Creates an OCR object
  OCRObj = OCR["CreateObject"](Rect)

  // Creates an OCROptions object
  OCROptions = OCRObj["CreateOptions"]();

  // Specifies that the FindRectByText method will not search for exact matches
  OCROptions["ExactSearch"] = false;

  // Specifies the comparison accuracy
  OCROptions["SearchAccuracy"] = 0.3;

  // Searches for the rectangle that contains the "Test" string
  var FindResult = OCRObj["FindRectByText"]("Test", OCROptions);
  if (FindResult)
  {
    // Obtains the coordinates and the size of the found rectangle
    X = OCRObj["FoundLeft"];
    Y = OCRObj["FoundTop"];
    dX = OCRObj["FoundWidth"];
    dY = OCRObj["FoundHeight"];

    RectResult = Window["Picture"](X, Y, dX, dY);
    // Posts the found rectangle to the test log
    Log["Picture"](RectResult, "Region with the found text:");
  }
}

See Also

FindRectByText Method
SearchAccuracy Property
Optical Character Recognition
Using Optical Character Recognition - Tips

Highlight search results