Simulating Selection of Items and Nodes

Applies to TestLeft 4.72, last modified on December 21, 2020

You can simulate selection of control items and nodes by using special methods of supported controls, native methods and properties of controls or by sending keystrokes to the needed control. This topic describes these approaches so that you can select the one that fits your needs best.

By Using Methods of the Appropriate Test Interfaces

TestLeft provides a number of test interfaces to work with controls that contain items and nodes: ITreeView, IListBox, and others. These interfaces provide methods and properties you can use to simulate various actions over controls, including simulating selection of items:

To select … Use …
A combo box item The ClickItem method provided by the IComboBox interface.
A list box item The ClickItem, ClickItemXY, DblClickItem, or DblClickItemXY method provided by the IListBox interface.
A tree view item The ClickItem, DblClickItem or DblClickItemR method provided by the ITreeView interface.
— or —
the Click, DblClick, or ClickR method provided by the ITreeViewItem interface.

TestLeft provides a number of classes to work with controls that contain items and nodes: TreeView, ListBox, and others. These interfaces provide methods and properties you can use to simulate various actions over controls, including simulating selection of items:

To select … Use …
A combo box item The clickItem method provided by the ComboBox class.
A list box item The clickItem, clickItemXY, dblClickItem, or dblClickItemXY method provided by the ListBox class.
A tree view item The clickItem, dblClickItem or dblClickItemR method provided by the TreeView class.
— or —
the click, dblClick, or clickR method provided by the TreeViewItem class.
By Sending Keystrokes

You can use keystrokes to simulate selection of items and nodes. See Simulating Keystrokes.

By Using Native Methods

If your tested application is prepared for testing and TestLeft is able to access its internal properties and methods, you can use the application’s native methods to simulate the needed user actions.

Example

The following sample code demonstrates how to simulate selecting an item from the Font list of the Notepad application (Notepad must be running and the Font dialog must be open):

C#

using SmartBear.TestLeft;
using SmartBear.TestLeft.TestObjects;


public void Test()
{
  IComboBox comboBox = Driver.Find<IProcess>(new ProcessPattern()
  {
    ProcessName = "notepad"
  }).Find<ITopLevelWindow>(new WindowPattern()
  {
    WndClass = "#32770",
    WndCaption = "Font"
  }).Find<IComboBox>(new WindowPattern()
  {
    WndClass = "ComboBox",
    Index = 1
  });

  comboBox.ClickItem("Arial");
}

Visual Basic .NET

Imports SmartBear.TestLeft
Imports SmartBear.TestLeft.TestObjects


Public Sub Test()
  Dim comboBox As IComboBox = Driver.Find(Of IProcess)(New ProcessPattern() With {
          .ProcessName = "notepad"
  }).Find(Of ITopLevelWindow)(New WindowPattern() With {
          .WndClass = "#32770",
          .WndCaption = "Font"
  }).Find(Of IComboBox)(New WindowPattern() With {
          .WndClass = "ComboBox",
          .Index = 1
  })

  comboBox.ClickItem("Arial")
End Sub

Java

import com.smartbear.testleft.*;
import com.smartbear.testleft.testobjects.*;



@Test
public void Test() throws Exception{
  ComboBox comboBox = driver.find(TestProcess.class, new ProcessPattern() {{
    ProcessName = "notepad";
  }}).find(TopLevelWindow.class, new WindowPattern() {{
    WndClass = "#32770";
    WndCaption = "Font";
  }}).find(ComboBox.class, new WindowPattern() {{
    WndClass = "ComboBox";
    Index = 1;
  }});

  comboBox.clickItem("Arial");
}

Capturing Tested Application Screenshots

It may be difficult to determine the state of the tested window or control before simulating user actions. You can enable TestLeft Visualizer to capture images of the tested windows and controls automatically.

See Also

Simulating User Actions
Simulating Keystrokes
Creating TestLeft Tests
About Driver Objects
Object Identification

Highlight search results