Getting the Scroll Box's Position in Desktop Windows Applications

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

Working with a scroll bar control implies changing the position of the scroll box. When testing a scroll bar control, you may need to determine the current scroll box’s position or estimate the available scrolling range.

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.

You can use specific properties and methods of the Win32ScrollBar object to obtain information and perform actions over the tested scroll bar. TestComplete associates this object with all scroll bar controls whose class names are listed in the Object Mapping list of the project’s options.

The following properties of the Win32ScrollBar object let you obtain information about the scroll box’s position:

  • wMin returns the minimum allowed position of the scroll box.
  • wPosition returns the current position of the scroll box.
  • wMax returns the maximum allowed position of the scroll box.

The following code snippet obtains information about the scroll box’s position and the scrolling range, and posts them to the test log:

JavaScript, JScript

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

  // Obtain the scroll box's positions and post them to the log
  Log.Message("Minimum Position: " + ScrollBar.wMin);
  Log.Message("Current Position: " + ScrollBar.wPosition);
  Log.Message("Maximum Position: " + ScrollBar.wMax);
}

Python

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

  # Obtain the scroll box's positions and post them to the log 
  Log.Message("Minimum Position: " + ScrollBar.wMin)
  Log.Message("Current Position: " + ScrollBar.wPosition)
  Log.Message("Maximum Position: " + ScrollBar.wMax)

VBScript

Sub Main
Dim p, w, ScrollBar

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

  ' Obtain the scroll box's positions and post them to the log
  Log.Message("Minimum Position: " & ScrollBar.wMin)
  Log.Message("Current Position: " & ScrollBar.wPosition)
  Log.Message("Maximum Position: " & ScrollBar.wMax)
End Sub

DelphiScript

procedure Main();
var
  p, w, ScrollBar: OleVariant;
begin 
  // Obtain the scroll bar object
  p := Sys.Process('MyApp');
  w := p.Window('TForm1');
  ScrollBar := w.Window('TScrollBar');

  // Obtain the scroll box's positions and post them to the log
  Log.Message('Minimum Position: ' + aqConvert.VarToStr(ScrollBar.wMin));
  Log.Message('Current Position: ' + aqConvert.VarToStr(ScrollBar.wPosition));
  Log.Message('Maximum Position: ' + aqConvert.VarToStr(ScrollBar.wMax));
end;

C++Script, C#Script

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

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

  // Obtain the scroll box's positions and post them to the log
  Log["Message"]("Minimum Position: " + ScrollBar["wMin"]);
  Log["Message"]("Current Position: " + ScrollBar["wPosition"]);
  Log["Message"]("Maximum Position: " + ScrollBar["wMax"]);
}

See Also

Working With Scroll Bar Controls in Desktop Windows Applications
wMin Property (ScrollBar Controls)
wMax Property (ScrollBar Controls)
wPosition Property (ScrollBar Controls)

Highlight search results