ClickItem Action (Specific to QtTreeWidget Controls)

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Moves the mouse pointer to the item specified by the Item parameter in the column specified by the Column parameter, and then simulates a single click of the left mouse button over the item.

Declaration

TestObj.ClickItem(Item, Column, Shift)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
Item [in]    Required    Variant    
Column [in]    Required    Variant    
Shift [in]    Optional    TShiftKey Default value: skNoShift   
Result None

Applies To

The method is applied to the following object:

View Mode

This method is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.

Parameters

The method has the following parameters:

Item

Specifies the path to the desired item. The path should be relative to the current item or to the tree root, respectively. To indicate that the path starts from the tree root, place the pipeline character ( | ) at the beginning of the path.

Each item in the path can be specified by its caption or index; individual captions and indexes must be separated with pipeline characters ( | ). Indexes must be enclosed in brackets - [ and ].

To indicate variable parts of the item caption, you can use the asterisk (*) and question mark (?) wildcards. The asterisk corresponds to a string of any length, the question mark corresponds to any single character. The caption can be case-sensitive or case-insensitive depending on the value of the Use case-sensitive parameters project setting.

Note: If the item caption includes a bracket or a pipeline character, address the item by its index or with the question mark wildcard.

Column

Specifies the column to be clicked. This parameter takes the column’s index or caption.

The index is zero-based and corresponds to the column’s position within the object's internal columns collection rather than the column’s visible position in the object.

The caption can contain asterisk (*) or question mark (?) wildcards or regular expressions. The asterisk corresponds to a string of any length, the question mark corresponds to any single character. To specify more complicated parts of a caption, use regular expressions.

The caption can be case-sensitive or case-insensitive depending on the value of the Use case-sensitive parameters project setting.

Shift

Specifies whether the CTRL, ALT or SHIFT key will be pressed during the click. The default value is skNoShift (no Shift key is pressed). See TShiftKey.

Result Value

None.

Remarks

If the item is not found, the method fails and posts an error message to the test log.

In certain cases, the ClickItem method may expand or collapse the specified tree node rather than select it. This can happen due to certain limitations of Qt controls. The method cannot detect the size and location of the “plus” (or “minus”) button and simulates a click on it. This expands or collapses the node instead of selecting it. To solve the problem, use the ClickItemXY method.

Example

The following example demonstrates how to use the ClickItem method. Suppose you have a tree widget control, MyTreeWidget, that has a structure as shown in the figure below.

A tree widget structure

A tree widget control combines the functionality of a typical tree view control and of a grid, that is, it can have expandable rows. To perform a click on a certain tree widget item, you should specify an item (actually, a row where the specified item resides), and the column where the click will be performed.

There are several ways to click the desired tree widget item. Assume, you need to click the items named SubItem1.2.1 and SubItem2.2.1, which reside in different columns of the same row (the first subitem of the second subitem of the first root item). You can do this in different ways:

  • Use the indexes of root items and their subitems:

    JavaScript, JScript

      // Clicks SubItem1.2.1
      MyTreeWidget.ClickItem("|[0]|[1]|[0]", 0);
      // Clicks SubItem 2.2.1
      MyTreeWidget.ClickItem("|[0]|[1]|[0]", 1);

    Python

      # Clicks SubItem1.2.1
      MyTreeWidget.ClickItem("|[0]|[1]|[0]", 0)
      # Clicks SubItem 2.2.1
      MyTreeWidget.ClickItem("|[0]|[1]|[0]", 1);

    VBScript

      ' Clicks SubItem1.2.1
      MyTreeWidget.ClickItem "|[0]|[1]|[0]", 0
      ' Clicks SubItem 2.2.1
      MyTreeWidget.ClickItem "|[0]|[1]|[0]", 1

    DelphiScript

      // Clicks SubItem1.2.1
      MyTreeWidget.ClickItem('|[0]|[1]|[0]', 0);
      // Clicks SubItem 2.2.1
      MyTreeWidget.ClickItem('|[0]|[1]|[0]', 1);

    C++Script, C#Script

      // Clicks SubItem1.2.1
      MyTreeWidget.ClickItem("|[0]|[1]|[0]", 0);
      // Clicks SubItem 2.2.1
      MyTreeWidget.ClickItem("|[0]|[1]|[0]", 1);

  • Use the captions of root items and their subitems:

    JavaScript, JScript

      // Clicks SubItem1.2.1
      MyTreeWidget.ClickItem("|TopItem1|SubItem1.2|SubItem1.2.1", 0);
      // Clicks SubItem 2.2.1
      MyTreeWidget.ClickItem("|TopItem1|SubItem1.2|SubItem2.2.1", 1);

    Python

      # Clicks SubItem1.2.1
      MyTreeWidget.ClickItem("|TopItem1|SubItem1.2|SubItem1.2.1", 0)
      # Clicks SubItem 2.2.1
      MyTreeWidget.ClickItem("|TopItem1|SubItem1.2|SubItem2.2.1", 1)

    VBScript

      ' Clicks SubItem1.2.1
      MyTreeWidget.ClickItem "|TopItem1|SubItem1.2|SubItem1.2.1", 0
      ' Clicks SubItem 2.2.1
      MyTreeWidget.ClickItem "|TopItem1|SubItem1.2|SubItem2.2.1", 1

    DelphiScript

      // Clicks SubItem1.2.1
      MyTreeWidget.ClickItem('|TopItem1|SubItem1.2|SubItem1.2.1', 0);
      // Clicks SubItem 2.2.1
      MyTreeWidget.ClickItem('|TopItem1|SubItem1.2|SubItem2.2.1', 1);

    C++Script, C#Script

      // Clicks SubItem1.2.1
      MyTreeWidget.ClickItem("|TopItem1|SubItem1.2|SubItem1.2.1", 0);
      // Clicks SubItem 2.2.1
      MyTreeWidget.ClickItem("|TopItem1|SubItem1.2|SubItem2.2.1", 1);

You can also combine indexes and captions while addressing tree widget items.

See Also

ClickItemR Action (Specific to QtTreeWidget Controls)
ClickItemM Action (Specific to QtTreeWidget Controls)
DblClickItem Action (Specific to QtTreeWidget Controls)

Highlight search results