How to check all checkboxes in UFT – ChildObjects in UFT

If you want to check all checkboxes in UFT on a webpage, there are many ways to do that. One of the most used approaches to handle this scenario is to use the concept of childobjects of UFT.

UFT provides a lot of capabilities inbuilt into the software yet we require some small code blocks to perform some very common tasks for test automation. Let’s see how we can check all checkboxes in UFT

What is childobjects in UFT?

Instead of pointing to the exact object on the webpage, UFT/QTP provides a mechanism to the users in which you can simply provide some attributes to find on the page. You can provide some common attributes and QTP will return a collection object with all the objects stored with matching attributes. For example, you want to find all the citizens of India having the birth year 1987 and the govt returns you a collection of records of citizens having a year of birth in 1987. Now you can open the file of each citizen and perform some operation or do anything with that information.

How to check all checkboxes in UFT.

Considering the fact that normally all the checkboxes have an HTML tag as “INPUT”. As we know the checkbox is called “WebCheckBox” in the QTP/UFT language. First, we will create a description object oWebChkDesc and feed this information to it so that allcCheck object has all the checkboxes.

Now we will run a for loop till the count of checkboxes in allCheck object and Set all of them as ON. See the code below.

Example code to check all checkboxes in UFT
Function checkAllCheckbox()
  Dim oWebChkDesc
  Set oWebChkDesc = Description.Create
  oWebChkDesc("micclass").value = "WebCheckBox"
  oWebChkDesc("html tag").Value = "INPUT"


  ' Get all the matching the description of the object
  Dim allCheck, oCheckBox
  Set allCheck = Browser("Web Tours").Page("Web Tours").ChildObjects(oWebChkDesc)
  For i = 0 to allCheck.Count - 1
  Set oCheckBox = allCheck(i)
  oCheckBox.Set "ON"
  Next
End Function

You may also read

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.