ExactSearch Property

Applies to TestComplete 12.60, last modified on September 17, 2018
The Optical Character Recognition feature provided by the OCR plugin is deprecated. It was removed from TestComplete in version 12.60 and is no longer available for later versions.
Instead, TestComplete version 12.60 introduces the new Optical Character Recognition engine featuring Google Cloud Vision API. To learn more, see Optical Character Recognition.
If you need to use the legacy feature, please contact our Customer Care team.

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