Finding Web Objects Using Specific Find Method

Applies to TestComplete 14.50, last modified on April 22, 2021
Information in this topic applies to web applications.

This topic explains how you can search for the needed elements on the tested web page with the specific Page.NativeWebObject.Find method.

About the Page.NativeWebObject.Find Method

The Page.NativeWebObject.Find method allows you to find a web page element by its native property, such as title, outerHTML, value, and so on. Native properties of web page objects are displayed in the Internet Explorer, Edge, Firefox, or Chrome category in the Object Browser (depending on the browser in which the web page is displayed).

There can be issues when property and attribute values returned by the browser differ from those defined in the web page’s source code. For more information on such issues, see Important Notes.

You can also search for Flash, Flex, Silverlight, Java and JavaFX web objects using their native properties and fields displayed under the Flex, Silverlight and Java categories. Note that Flash and Flex properties that are accessible via the FlexObject property cannot be specified as sought-for properties in Page.NativeWebObject.Find. If you want to perform a search by any of these properties, use common Find methods.

The method returns the found object as a result. If no matching object was found, the method returns an empty “stub” object. To determine whether the search was successful, check the Exists property value of the returned object. If the page contains several objects that correspond to the search criteria, the method returns the first found object.

If you want to call this method from your keyword tests, use the Call Object Method operation.

Example

The sample script below demonstrates how you can use the Page.NativeWebObject.Find method to find a link on a web page:

JavaScript, JScript

function Test()
{

  var url = "http://smartbear.com/";

  // Launch Internet Explorer if it is not running
  if (! Sys.WaitBrowser("iexplore", 10000).Exists)
    Browsers.Item(btIExplorer).Run(url);
  else
    Browsers.Item(btIExplorer).Navigate(url);

  var page = Sys.Browser("*").Page(url);

  // Find and click the "Products" link
  var link = page.NativeWebObject.Find("contentText", "Products", "a");
  link.Click();
}

Python

def Test():
  url = "http://smartbear.com/"

  # Launch Internet Explorer if it is not running
  if not Sys.WaitBrowser("iexplore", 10000).Exists:
    Browsers.Item[btIExplorer].Run(url)
  else:
    Browsers.Item[btIExplorer].Navigate(url)

  page = Sys.Browser("*").Page(url)

  # Find and click the "Products" link
  link = page.NativeWebObject.Find("contentText", "Products", "a")
  link.Click()

VBScript

Sub Test
  Dim url, page, link

  url = "http://smartbear.com/"

  ' Launch Internet Explorer if it is not running
  If Not Sys.WaitBrowser("iexplore", 10000).Exists Then
    Browsers.Item(btIExplorer).Run url
  Else
    Browsers.Item(btIExplorer).Navigate url
  End If

  Set page = Sys.Browser("*").Page(url)

  ' Find and click the "Products" link
  Set link = page.NativeWebObject.Find("contentText", "Products", "a")
  link.Click
End Sub

DelphiScript

procedure FindNativeSample;
var url, page, link;
begin

  url := 'http://smartbear.com/';

  // Launch Internet Explorer if it is not running
  if not Sys.WaitBrowser('iexplore', 10000).Exists then
    Browsers.Item[btIExplorer].Run(url)
  else
    Browsers.Item[btIExplorer].Navigate(url);

  page := Sys.Browser('*').Page(url);

  // Find and click the 'Products' link
  link := page.NativeWebObject.Find('contentText', 'Products', 'a');
  link.Click;
end;

C++Script, C#Script

function Test()
{

  var url = "http://smartbear.com/";

  // Launch Internet Explorer if it is not running
  if (! Sys["WaitBrowser"]("iexplore", 10000).Exists)
    Browsers["Item"](btIExplorer)["Run"](url);
  else
    Browsers["Item"](btIExplorer)["Navigate"](url);

  var page = Sys["Browser"]("*")["Page"](url);

  // Find and click the "Products" link
  link = page["NativeWebObject"]["Find"]("contentText", "Products", "a");
  link["Click"]();
}

See Also

Find Web Objects
Finding Web Objects Using Common Find Methods
Access Native Web Attributes and Methods
How To
Default Web Testing

Highlight search results