Applies to TestComplete 14.60, last modified on September 18, 2020

Description

The Cell property returns the OCRTextBlock object that describes a block of the text recognized in a table cell specified by its row index and column index.

Declaration

OCRTableObj.Cell(RowIndexColumnIndex)

Read-Only Property An OCRTextBlock object
OCRTableObj An expression, variable or parameter that specifies a reference to an OCRTable object
RowIndex [in]    Required    Integer    
ColumnIndex [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameters:

RowIndex

Specifies the index of the row that contains the needed cell.

The index is zero-based, that is, the first row has index 0, the second one has index 1, and so on. The index of the last visible row is RowCount - 1.

ColumnIndex

Specifies the index of the column that contains the needed cell.

The index is zero-based, that is, the first column has index 0, the second one has index 1, and so on. The index of the last visible column is ColumnCount - 1.

Property Value

An OCRTextBlock object that describes the recognized text content of the specified table cell.

Example

The following example shows how to use optical character recognition to get the text content of the first cell of a table and post it to the test log:

JavaScript, JScript

function Main()
{
  // Navigate to the tested web page
  var url = "https://www.w3schools.com/html/tryit.asp?filename=tryhtml_table_border";
  Browsers.Item("chrome").Run(url);

  // Get the page area containing the table
  var page = Sys.Browser("chrome").Page("*");
  var gridArea = page.FindChild("idStr", "iframeresult", 10);

  if (gridArea != null)
  {
    // Specify whether the table has a header
    var hasHeader = true;
    // Specify the preferable search area
    var searchPref = spNone;
    // Recognize the table content
    var table = OCR.Recognize(gridArea).DetectTable(searchPref, hasHeader);

    // Post the first cell content to the test log
    if (table.RowCount > 0 && table.ColumnCount > 0)
      Log.Message(table.Cell(0, 0).Text);
    else
      Log.Warning("The table is empty");
  }
  else
    Log.Warning("Cannot obtain the search area.");
}

Python

def Main():
  # Navigate to the test web page
  url = "https://www.w3schools.com/html/tryit.asp?filename=tryhtml_table_border"
  Browsers.Item["chrome"].Run(url)

  # Get the page area containing the table
  page = Sys.Browser("chrome").Page("*")
  gridArea = page.FindChild("idStr", "iframeresult", 10)

  if (gridArea != None):
    # Specify whether the table has a header
    hasHeader = True
    # Specify the preferable search area
    searchPref = spNone
    # Recognize the table contents
    table = OCR.Recognize(gridArea).DetectTable[searchPref, hasHeader]

    # Post the first cell contents to the test log
    if (table.RowCount > 0 and table.ColumnCount> 0):
      Log.Message(table.Cell[0, 0].Text)
    else:
      Log.Warning("The table is empty")
  else:
    Log.Warning("Cannot obtain the search area.")

VBScript

Sub Main
  ' Navigate to the tested web page
  url = "https://www.w3schools.com/html/tryit.asp?filename=tryhtml_table_border"
  Browsers.Item("chrome").Run(url)

  ' Get the page area containing the table
  Set page = Sys.Browser("chrome").Page("*")
  Set gridArea = page.FindChild("idStr", "iframeresult", 10)

  If Not gridArea Is Nothing Then
    ' Specify whether the table has a header
    hasHeader = True
    ' Specify the preferable search area
    searchPref = spNone
    ' Recognize the table content
    Set table = OCR.Recognize(gridArea).DetectTable(searchPref, hasHeader)

    ' Post the first cell content to the test log
    If table.RowCount > 0 And table.ColumnCount > 0 Then
      Log.Message(table.Cell(0, 0).Text)
    Else
      Log.Warning("The table is empty")
    End If

  Else
    Log.Warning("Cannot obtain the search area.")
  End If
End Sub

DelphiScript

procedure Main();
var url, page, gridArea, hasHeader, searchPref, table;
begin
  // Navigate to the tested web page
  url := 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_table_border';
  Browsers.Item('chrome').Run(url);

  // Get the page area containing the table
  page := Sys.Browser('chrome').Page('*');
  gridArea := page.FindChild('idStr', 'iframeresult', 10);

  if gridArea <> nil then
  begin
    // Specify whether the table has a header
    hasHeader := true;
    // Specify the preferable search area
    searchPref := spNone;
    // Recognize the table content
    table := OCR.Recognize(gridArea).DetectTable(searchPref, hasHeader);

    // Post the first cell content to the test log
    if ((table.RowCount > 0) and (table.ColumnCount > 0)) then
      Log.Message(table.Cell(0, 0).Text)
    else
      Log.Warning('The table is empty')

  end
  else
    Log.Warning('Cannot obtain the search area.');
end;

C++Script, C#Script

function Main()
{
  // Navigate to the tested web page
  var url = "https://www.w3schools.com/html/tryit.asp?filename=tryhtml_table_border";
  Browsers["Item"]("chrome")["Run"](url);

  // Get the page area containing the table
  var page = Sys["Browser"]("chrome")["Page"]("*");
  var gridArea = page["FindChild"]("idStr", "iframeresult", 10);

  if (gridArea != null)
  {
    // Specify whether the table has a header
    var hasHeader = true;
    // Specify the preferable search area
    var searchPref = spNone;
    // Recognize the table content
    var table = OCR.Recognize(gridArea).DetectTable(searchPref, hasHeader);

    // Post the first cell content to the test log
    if (table["RowCount"] > 0 && table["ColumnCount"] > 0)
      Log["Message"](table.Cell(0, 0).Text);
    else
      Log["Warning"]("The table is empty");
  }
  else
    Log["Warning"]("Cannot obtain the search area.");
}

See Also

OCRTable Object
ColumnCount Property
RowCount Property
Optical Character Recognition

Highlight search results