Getting an IP Address

Applies to TestComplete 14.71, last modified on April 22, 2021

While testing IP Address 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.

To obtain the IP address displayed in the IP Address control, use the wAddress property of the Win32IPAddress object. TestComplete associates this object with all IP Address controls whose class names are listed in the Object Mapping options of your project. The wAddress property returns a text string containing the IP address that is displayed in the control.

The text string returned by wAddress has the format nnn.nnn.nnn.nnn, where nnn is a three-digit number within the range from 0 to 255. The numbers are separated by periods.

Below is an example that demonstrates how you can obtain the address that is currently displayed in the IP Address control located in the operating system's Internet Protocol (TCP/IP) Properties window and is labeled IP address:

JavaScript, JScript

function main()
{
  var IPAddress;
    
  // Obtain the IP Address control
  IPAddress = Sys.Process("Explorer").Window("#32770", "Internet Protocol (TCP/IP) Properties", 1).Window("#32770", "General", 1).Window("SysIPAddress32", "", 1);
    
  // Get the IP address
  Log.Message(IPAddress.wAddress);
}

Python

def main():
    
  # Obtain the IP Address control
  IPAddress = Sys.Process("Explorer").Window("#32770", "Internet Protocol (TCP/IP) Properties", 1).Window("#32770", "General", 1).Window("SysIPAddress32", "", 1)
    
  # Get the IP address
  Log.Message(IPAddress.wAddress)

VBScript

Sub main
  Dim IPAddress
    
  ' Obtain the IP Address control
  Set IPAddress = Sys.Process("Explorer").Window("#32770", "Internet Protocol (TCP/IP) Properties", 1).Window("#32770", "General", 1).Window("SysIPAddress32", "", 1)

  ' Get the IP address
  Log.Message IPAddress.wAddress
End Sub

DelphiScript

procedure main;
var IPAddress;
begin
  
  // Obtain the IP Address control
  IPAddress := Sys.Process('Explorer').Window('#32770', 'Internet Protocol (TCP/IP) Properties', 1).Window('#32770', 'General', 1).Window('SysIPAddress32', '', 1);
       
  // Get the IP address
  Log.Message(IPAddress.wAddress);
end;

C++Script, C#Script

function main()
{
  var IPAddress;
    
  // Obtain the IP Address control
  IPAddress = Sys["Process"]("Explorer")["Window"]("#32770", "Internet Protocol (TCP/IP) Properties", 1)["Window"]("#32770", "General", 1)["Window"]("SysIPAddress32", "", 1);
  
  // Get the IP address
  Log.Message(IPAddress["wAddress"]);
}

See Also

Working With IP Address Controls
wAddress Property (IPAddress Controls)

Highlight search results