Identifying web objects in TestComplete

TestComplete provides you with several search methods that let you find certain object on the tested web page. Following are the methods available in TestComplete to identify the web objects in the test page

1. Using Common Find Methods
2. Using Specific Find Method
3. Using XPath Expressions
4. Using CSS Selectors

Here we're talking about the method 2, Using Specific Find Method. Its syntax is
TestObj.NativeWebObject.Find(PropertyName, KeyValue)
TestObj - Page to be tested
Property Name - Property Name of the control
KeyValue - Property Value of the object

Lets look how we can do this, In previous post we've created the first script using TestComplete, We can add below task in the same script which help to learn NativeWebOject method

Task details
Task 1. Identify google search text box and enter keyword.
Task 2. Identify google search button and perform button click.

To identify the object properties, TestComplete provide the spy button which can be invoked by click the  Display Object Spy button on the Tools toolbarDrag the target glyph to the desired object.
Here first place on it search box and identify the property name and value, as shown below. Identify a unique property of both controls, here we're selecting ObjectIdentifier, 

Here is code snippet,
function Main() {
Browsers.Item("firefox").Run("https://www.goole.com");
page=Sys.Browser("firefox").Page("https://www.goole.com");
page.wait();

if(page.exists)
 {
   //Task 1
   var searchTxt = page.NativeWebObject.Find("ObjectIdentifier","lst_ib")
   searchTxt.setText("car")
   
   //Task 2
   var searchBtn = page.NativeWebObject.Find("ObjectIdentifier","btnK")
   searchBtn.Click()

   Log.Message("URL has been successfully loaded")
 }
else
 {
   Log.Message("Failed to load the URL")
 }
}
Check the Task 1, identified google search box using ObjectIdentfier property and its value and entered keyword with setText() method. In Task 2, identified in the same way and clicked on the button using click() method.

Share this