Changing Seek Bar Position

Applies to TestComplete 15.46, last modified on January 09, 2023
Assigning wPosition Property

To assign a seek bar slider position, use the wPosition property. This property allows you to specify a value between the minimum and the maximum values of the seek bar. When you assign the position, no message is added to the test log.

JavaScript, JScript

function Test()
{
  // Select the Android device
  Mobile.SetCurrent("MyDevice");
   
  // Obtain the SeekBar object
  var p = Mobile.Device().Process("com.example.myapp");
  var SeekBar = p.RootLayout("").Layout("layoutTop").Layout("layout2").SeekBar("seekbar1");
  
  // Assign the new value to the wPosition property
  SeekBar.wPosition = 10;
}

Python

def Test():
  # Select the Android device
  Mobile.SetCurrent("MyDevice")
   
  # Obtain the SeekBar object
  p = Mobile.Device().Process("com.example.myapp")
  SeekBar = p.RootLayout("").Layout("layoutTop").Layout("layout2").SeekBar("seekbar1")
  
  # Assign the new value to the wPosition property
  SeekBar.wPosition = 10

VBScript

Sub Test()
  Dim p, SeekBar
  
  ' Select the Android device
  Mobile.SetCurrent("MyDevice")
   
  ' Obtain the SeekBar object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set SeekBar = p.RootLayout("").Layout("layoutTop").Layout("layout2").SeekBar("seekbar1")
  
  ' Assign the new value to the wPosition property
  SeekBar.wPosition = 10
End Sub

DelphiScript

procedure Test();
var 
  p, SeekBar : OleVariant;
begin
  // Select the Android device
  Mobile.SetCurrent('MyDevice');
   
  // Obtain the SeekBar object
  p := Mobile.Device.Process('com.example.myapp');
  SeekBar := p.RootLayout('').Layout('layoutTop').Layout('layout2').SeekBar('seekbar1');
  
  // Assign the new value to the wPosition property
  SeekBar.wPosition := 10;
end;

C++Script, C#Script

function Test()
{
  // Select the Android device
  Mobile["SetCurrent"]("MyDevice");
   
  // Obtain the SeekBar object
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var SeekBar = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout2")["SeekBar"]("seekbar1");
  
  // Assign the new value to the wPosition property
  SeekBar["wPosition"] = 10;
}

If you try to assign the value above wMax or below wMin, the error message will be posted to the log and the wMax or wMin value will be assigned instead.
Simulating Touch Action

To touch a seek bar, use the Touch action of the AndroidSeekBar object that TestComplete associates with that control. This action performs a single short touch on a control in the position specified by X and Y parameters. If no parameters are set, the touch is performed in the middle of the control. To determine the touch position, divide the width of the control by its maximum position, and then multiply by the required position. The following example shows how to simulate a touch over the seek bar:

JavaScript, JScript

function Test()
{
  // Select the Android device
  Mobile.SetCurrent("MyDevice");
  
  // Obtain the SeekBar object
  var p = Mobile.Device().Process("com.example.myapp");
  var SeekBar = p.RootLayout("").Layout("layoutTop").Layout("layout2").SeekBar("seekbar1");
  
  // Obtain the coordinates for the touch
  var TouchPos = (SeekBar.Width/SeekBar.wMax)*50;
  
  // Touch the SeekBar at the coordinates
  SeekBar.Touch(TouchPos, 10);
}

Python

def Test():
  # Select the Android device
  Mobile.SetCurrent("MyDevice")
  
  # Obtain the SeekBar object
  p = Mobile.Device().Process("com.example.myapp")
  SeekBar = p.RootLayout("").Layout("layoutTop").Layout("layout2").SeekBar("seekbar1")
  
  # Obtain the coordinates for the touch
  TouchPos = (SeekBar.Width/SeekBar.wMax)*50
  
  # Touch the SeekBar at the coordinates
  SeekBar.Touch(TouchPos, 10)

VBScript

Sub Test()
  Dim p, SeekBar, TouchPos

  ' Select the Android device
  Call Mobile.SetCurrent("MyDevice")
  
  ' Obtain the SeekBar object
  Set p = Mobile.Device.Process("com.example.myapp")
  Set SeekBar = p.RootLayout("").Layout("layoutTop").Layout("layout2").SeekBar("seekbar1")
  
  ' Obtain the coordinates for the touch
  TouchPos = (SeekBar.Width/SeekBar.wMax)*50
  
  'Touch the SeekBar at the coordinates
  Call SeekBar.Touch(TouchPos, 10)
End Sub

DelphiScript

procedure Test();
var 
  p, SeekBar, TouchPos : OleVariant;
begin
  // Select the Android device
  Mobile.SetCurrent('MyDevice');
  
  // Obtain the SeekBar object
  p: = Mobile.Device.Process('com.example.myapp');
  SeekBar := p.RootLayout('').Layout('layoutTop').Layout('layout2').SeekBar('seekbar1');
  
  // Obtain the coordinates for the touch
  TouchPos := (SeekBar.Width/SeekBar.wMax)*50;
  
  // Touch the SeekBar at the coordinates
  SeekBar.Touch(TouchPos, 10);
end;

C++Script, C#Script

function Test()
{
  // Select the Android device
  Mobile["SetCurrent"]("MyDevice");
  
  var p = Mobile["Device"]["Process"]("com.example.myapp");
  var SeekBar = p["RootLayout"]("")["Layout"]("layoutTop")["Layout"]("layout2")["SeekBar"]("seekbar1");
  
  // Obtain the coordinates for the touch
  var TouchPos = (SeekBar["Width"]/SeekBar["wMax"])*50;
  
  // Touch the SeekBar at the coordinates
  SeekBar["Touch"](TouchPos, 10);
}

Using From Keyword Tests

This topic explains how to change the position of the seek bar control in scripts. You can use the described methods and properties in keyword tests too. To do this, use the On-Screen Action or the Call Object Method operations.

See Also

Working With Android Seek Bar Controls
Determining the Seek Bar Position

Highlight search results