Column Property

Applies to TestComplete 15.46, last modified on January 09, 2023

Description

The Column property returns the OCRTextBlock object that describes the header of the table’s column that TestComplete recognizes by using optical character recognition.

If the table does not have a header (you specify it when you get the table by calling the AsTable or DetectTable property), the property will post an error to the test log.

Declaration

OCRTableObj.Column(Index)

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

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

Specifies the index of the column whose header you want to get.

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 the column header.

If the table has no header, the property will post an error to the test log.

Example

The following example shows how to get the table headers and post them 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 column captions to the test log
    if (table.ColumnCount > 0)
      for (var i = 0; i < table.ColumnCount; i++)
        Log.Message(table.Column(i).Text);

  }
  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 column captions to the test log
    if (table.ColumnCount > 0):
      for i in range (0, table.ColumnCount):
        Log.Message(table.Column[i].Text)
    
  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 column captions to the test log
    If table.ColumnCount > 0 Then
      For i = 0 To table.ColumnCount - 1
        Log.Message(table.Column(i).Text)
      Next
    End If

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

DelphiScript

procedure Main();
var url, page, gridArea, hasHeader, searchPref, table, i;
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 column captions to the test log
    if table.ColumnCount > 0 then
      for i := 0 to table.ColumnCount - 1 do
        Log.Message(table.Column(i).Text);

  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 column captions to the test log
    if (table["ColumnCount"] > 0)
      for (var i = 0; i < table["ColumnCount"]; i++)
        Log["Message"](table["Column"](i)["Text"]);

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

See Also

OCRTable Object
ColumnCount Property
Optical Character Recognition

Highlight search results