Micro Focus QTP (UFT) Forums
Count number of specific elements on a web page - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Count number of specific elements on a web page (/Thread-Count-number-of-specific-elements-on-a-web-page)



Count number of specific elements on a web page - janriis - 09-24-2010

Hi all

I have 2 web pages in my app that are almost identical. I cannot identify them by URL or objects as the objects are named runtime.

Page 1 has 3 web radio groups and page 2 has 6 web radio groups. My idea now is to count the number of elements i.e. web radio groups, but how do i do that with descriptive programming ?


RE: Count number of specific elements on a web page - QTPLearn - 09-27-2010

Hi

Use 'ChildItemCount' function.

Code:
ItemIndex=Obj.ChildItemCount(row, col, "WebRadioGroup")

Hope this will help you.

~Regards


RE: Count number of specific elements on a web page - janriis - 09-27-2010

Thx, I will give it a try


RE: Count number of specific elements on a web page - A.Saini - 09-27-2010

hi,

As per the above discussion, count function will give you the count of your desired elements.

Now before that,to differntiate the browers you can use ordinal identifiar (EX: Index).

Code:
Browser("Name:= abc","Index :=0").Page("innerhtml := def").Activate

Browser("Name:= abc","Index :=1").Page("innerhtml := def").Activate


Use the appropriate names.Hope it should work for you...
Smile


RE: Count number of specific elements on a web page - sreekanth chilam - 09-27-2010

Hi QTPLearn,

Do you really think that using "ChildItemCount" method would solve the Janris Question?

FYI, "ChildItemCount" method is applicable for Object classes such as WebTable,SAPTable,WbfGrid only.


RE: Count number of specific elements on a web page - QTPLearn - 09-28-2010

Hi Sreekant

I have used 'Child ItemCount' for my project for counting checkboxes,radiobuttons,webelements,thats why I suggested that but if you have any better solution then please provide it.

It will help all of us to learn new approach.

~Regards


RE: Count number of specific elements on a web page - sreekanth chilam - 09-28-2010

HI,
I would suggest to try in the below approach.

Code:
Set Brw=Description.Create
Brw("micclass").Value="Browser"

Set Pg=Description.Create
Pg("micclass").Value="Page"

Set Wrg=Description.Create
Wrg("micclass").Value="WebRadioGroup"

Set Brw_Collection=Desktop.ChildObjects(Brw)
msgbox "No. of Browsers: "& Brw_Collection.count

     Set Br1_Pgcollection=Brw_Collection(0).childObjects(Pg)
     Set Br1_Pg1_WrgCollection=Br1_Pgcollection(0).ChildObjects(Wrg)
     msgbox "No. of WebRadioGroups in Browser1,Page1 : "&Br1_Pg1_WrgCollection.count

     Set Br2_Pgcollection=Brw_Collection(1).childObjects(Pg)
     Set Br2_Pg2_WrgCollection=Br2_Pgcollection(0).ChildObjects(Wrg)
     msgbox "No. of WebRadioGroups in Browser2,Page2 : "&Br2_Pg2_WrgCollection.count



RE: Count number of specific elements on a web page - MVChowdary - 09-28-2010

Hi Sreekanth,

Good solution.