Scrolling Content in Desktop Windows Applications

Applies to TestComplete 15.63, last modified on April 23, 2024

While testing scroll bar controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

Scroll bar controls allow you to perform scrolling of the related window’s contents. Since TestComplete uses the Win32ScrollBar object to work with standard scroll bars, you can use a set of specific properties and methods provided by this object to work with scroll bar controls from your scripts. Generally, there are two approaches that you can use to change the scroll box position.

  • The first approach consists of moving the scroll box using various actions provided by the Win32ScrollBar object.

    • You can simulate clicking on the scroll bar or scroll arrows to move the scroll box in the needed direction. A click can be simulated via the Click action.
    • You can use the Keys action to simulate clicking on arrow keys, which moves the scroll box in the respective direction. For detailed information on how to simulate keystrokes, see Simulating Keystrokes.
    • Another possible way of scrolling is to estimate the coordinates of the needed position and drag the thumb to this position via the Drag action.
  • Another approach consists in specifying the scroll box position via the wPosition property of Win32ScrollBar. Before specifying a new position you can determine the current position of the scroll box and the scrolling range (see Getting the Scroll Box's Position in Desktop Windows Applications). Then you can estimate the needed position and set it by changing the wPosition property.

The following code demonstrates how to perform scrolling:

JavaScript, JScript

function Main()
{
var p, w, ScrollBar, Slider;

  // Obtain the scroll bar object
  p = Sys.Process("MyApp");
  w = p.Window("TForm1");
  ScrollBar = w.Window("TScrollBar");

  // Move the slider to the left
  ScrollBar.Keys("[Left][Left][Left][Left]");
   
  // Increase the slider position
  Slider = ScrollBar.wPosition + 4;
  ScrollBar.wPosition = Slider;
}

Python

def Main():

  # Obtain the scroll bar object
  p = Sys.Process("MyApp")
  w = p.Window("TForm1")
  ScrollBar = w.Window("TScrollBar")

  # Move the slider to the left
  ScrollBar.Keys("[Left][Left][Left][Left]")
   
  # Increase the slider position
  Slider = ScrollBar.wPosition + 4
  ScrollBar.wPosition = Slider

VBScript

Sub Main
Dim p, w, ScrollBar, Slider

  ' Obtain the scroll bar object
  Set p = Sys.Process("MyApp")
  Set w = p.Window("TForm1")
  Set ScrollBar = w.Window("TScrollBar")

  ' Move the slider to the left
  ScrollBar.Keys "[Left][Left][Left][Left]"
  
  ' Increase the slider position
  Slider = ScrollBar.wPosition + 4
  ScrollBar.wPosition = Slider
End Sub

DelphiScript

procedure Main();
var 
  p, w, ScrollBar, Slider: OleVariant;
begin 
  // Obtain the scroll bar object
  p := Sys.Process('MyApp');
  w := p.Window('TForm1');
  ScrollBar := w.Window('TScrollBar');
 
  // Move the slider to the left
  ScrollBar.Keys('[Left][Left][Left][Left]');
  
  // Increase the slider position
  Slider := ScrollBar.wPosition + 4;
  ScrollBar.wPosition := Slider;
end;

C++Script, C#Script

function Main()
{
var p, w, ScrollBar, Slider

  // Obtain the scroll bar object
  p = Sys["Process"]("MyApp");
  w = p["Window"]("TForm1");
  ScrollBar = w["Window"]("TScrollBar");

  // Move the slider to the left
  ScrollBar["Keys"]("[Left][Left][Left][Left]");
  
  // Increase the slider position
  Slider = ScrollBar["wPosition"] + 4;
  ScrollBar["wPosition"] = Slider;
}

See Also

Working With Scroll Bar Controls in Desktop Windows Applications
wPosition Property (ScrollBar Controls)
Click Action
Keys Action
Drag Action
Simulating Keystrokes

Highlight search results