ColumnCount Property

Applies to TestComplete 14.50, last modified on April 22, 2021

Description

The ColumnCount property returns the number of columns that the table recognized by using optical character recognition.

Declaration

OCRTableObj.ColumnCount

Read-Only Property Integer
OCRTableObj An expression, variable or parameter that specifies a reference to an OCRTable object

Applies To

The property is applied to the following object:

Property Value

The number of columns that the recognized table has.

Example

The example below uses the DetectTable property to recognize tabular data on a web page and then uses the ColumnCount and RowCount properties to iterate the data 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);

    // Call the routine that posts table data to the test log
    PrintTable(table);

  }
  else
    Log.Warning("Cannot obtain the search area.");
}

function PrintTable(aTable)
{
  if (aTable != null)
  {
    Log.AppendFolder("Table contents:");
    for (var i = 0; i < aTable.RowCount; i++)
    {
      for (var j = 0; j < aTable.ColumnCount; j++)
      {
        Log.Message(aTable.Cell(i, j).Text);
      }
    }
    Log.PopLogFolder();
  }
}

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]

    # Call the routine that post table data to the test log
    PrintTable(table)

  else:
    Log.Warning("Cannot obtain the search area.")

def PrintTable(aTable):
  if (aTable != None):
    Log.AppendFolder("Table contents:")
    for i in range (0, aTable.RowCount):
      for j in range (0, aTable.ColumnCount):
        Log.Message(aTable.Cell[i, j].Text)
    Log.PopLogFolder()

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)

    ' Call the routine that posts table data to the test log
    PrintTable(table)

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

Sub PrintTable(aTable)
  If Not aTable Is Nothing Then
    Log.AppendFolder("Table contents:")
    For i = 0 To aTable.RowCount - 1
      For j = 0 To aTable.ColumnCount - 1
        Log.Message(aTable.Cell(i, j).Text)
      Next
    Next
    Log.PopLogFolder
  End If
End Sub

DelphiScript

procedure PrintTable(aTable);
var i, j;
begin
  if aTable <> nil then
  begin
    Log.AppendFolder('Table contents:');
    for i := 0 to aTable.RowCount - 1 do
    begin
      for j := 0 to aTable.ColumnCount - 1 do
        Log.Message(aTable.Cell(i, j).Text);
    end;
    Log.PopLogFolder();
  
end;
end;
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);

    // Call the routine that posts table data to the test log
    PrintTable(table);

  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);

    // Call the routine that posts table data to the test log
    PrintTable(table);

  }
  else
    Log["Warning"]("Cannot obtain the search area.");
}

function PrintTable(aTable)
{
  if (aTable != null)
  {
    Log["AppendFolder"]("Table contents:");
    for (var i = 0; i < aTable["RowCount"]; i++)
    {
      for (var j = 0; j < aTable["ColumnCount"]; j++)
      {
        Log["Message"](aTable["Cell"](i, j)["Text"]);
      }
    }
    Log["PopLogFolder"]();
  }
}

See Also

OCRTable Object
Column Property
RowCount Property
Optical Character Recognition

Highlight search results