wSelection Property (Mobile Controls)

Applies to TestComplete 15.69, last modified on November 13, 2024
This property is available in legacy mobile tests that work with devices connected to the local computer. To learn how to simulate user actions in newer cloud-compatible mobile tests, see the Simulating user actions in tests section.

Description

Use the wSelection property to obtain the text, which is currently selected in the mobile text edit control. To get the starting and ending character positions of the selected text, use the wSelectionStart and wSelectionEnd properties, respectively.

To obtain the entire text displayed in the edit control, use the wText property.

Declaration

TestObj.wSelection

Read-Only Property String
TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section

Applies To

The property is applied to the following objects:

View Mode

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

Property Value

The text selected in the edit control. If no text is selected, the property returns an empty string.

Example

The code below demonstrates how you can obtain the text selected in the mobile EditText control by using the wSelection property:

JavaScript, JScript

function Test()
{
  // Select the mobile device
  Mobile.SetCurrent("MyDevice");

  // Obtain the EditText object and enter the text in it
  var p = Mobile.Device("MyDevice").Process("test.app");
  var edit = p.RootLayout("").EditText("edit1");
  edit.SetText("Do cats eat bats?");

  // Select a portion of the text by simulating a long touch over the control
  edit.LongTouch(5, 0);

  // Obtain the selected text and post it to the test log
  var selectedText = edit.wSelection;
  Log.Message(selectedText);
}

Python

def Test():
  # Select the mobile device
  Mobile.SetCurrent("MyDevice")

  # Obtain the EditText object and enter the text in it
  p = Mobile.Device("MyDevice").Process("test.app")
  edit = p.RootLayout("").EditText("edit1")
  edit.SetText("Do cats eat bats?")

  # Select a portion of the text by simulating a long touch over the control
  edit.LongTouch(5, 0)

  # Obtain the selected text and post it to the test log
  selectedText = edit.wSelection
  Log.Message(selectedText)

VBScript

Sub Test
  ' Select the mobile device
  Mobile.SetCurrent("MyDevice")

  ' Obtain the EditText object and enter the text in it
  Set p = Mobile.Device("MyDevice").Process("test.app")
  Set edit = p.RootLayout("").EditText("edit1")
  edit.SetText("Do cats eat bats?")

  ' Select a portion of the text by simulating a long touch over the control
  Call edit.LongTouch(5, 0)

  ' Obtain the selected text and post it to the test log
  selectedText = edit.wSelection
  Log.Message(selectedText)
End Sub

DelphiScript

procedure Test();
var p, edit, selectedText;
begin
  // Select the mobile device
  Mobile.SetCurrent('MyDevice');

  // Obtain the EditText object and enter the text in it
  p := Mobile.Device('MyDevice').Process('test.app');
  edit := p.RootLayout('').EditText('edit1');
  edit.SetText('Do cats eat bats?');

  // Select a portion of the text by simulating a long touch over the control
  edit.LongTouch(5, 0);

  // Obtain the selected text and post it to the test log
  selectedText := edit.wSelection;
  Log.Message(selectedText);

end;

C++Script, C#Script

function Test()
{
  // Select the mobile device
  Mobile["SetCurrent"]("MyDevice");
  // Obtain the EditText object and enter the text in it
  var p = Mobile["Device"]("MyDevice")["Process"]("test.app");
  var edit = p["RootLayout"]("")["EditText"]("edit1");
  edit["SetText"]("Do cats eat bats?");

  // Select a portion of the text by simulating a long touch over the control
  edit["LongTouch"](5, 0);

  // Obtain the selected text and post it to the test log
  var selectedText = edit["wSelection"];
  Log["Message"](selectedText);
}

See Also

Testing Android Applications (Legacy)
Testing iOS Applications (Legacy)
Selecting Text Within the Edit Text Control
Selecting Text Within an Edit Control
wText Property (Mobile Edit Controls)
wSelectionStart Property (Mobile Controls)
wSelectionEnd Property (Mobile Controls)

Highlight search results