Micro Focus QTP (UFT) Forums
Count number of webelement with specific names - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Count number of webelement with specific names (/Thread-Count-number-of-webelement-with-specific-names)



Count number of webelement with specific names - kalaivanan123 - 07-30-2012

Hi all..
I am having Webtable in page ..From that webtable I would like to count number of webelements with name of "PDF" or "XLS".

Code I am using,

Code:
Set Desc_Element = Description.Create()
Desc_Element("micclass").value = "WebElement"
Desc_Element("name").Value = ".*XLS.*"
Set Element= Browser("XXX").Page("XXX").WebTable("XXX").childobjects(Desc_Element )
MsgBox "Number of Elements: " & Element.Count

Now I'm getting Output is :- 5. Bcoz I defined only "XLS" in Description.
But I need the count of webelement object with the name of "PDF" as well as "XLS".
Pls help me to get solution for this.

attaching screenshot.PF


RE: Count number of webelement with specific names - ssvali - 07-30-2012

Try this...

Code:
Set Desc_Element = Description.Create()
Desc_Element("micclass").value = "WebElement"

Set Element= Browser("XXX").Page("XXX").WebTable("XXX").childobjects(Desc_Element )

For i = Lbound(Element) to Ubound(Element)

    objname = Element(i).GetROProperty("name")
    
    If instr(1,objname,"XLS") = 1 Then
        Cnt = Cnt + 1
    End If

    If instr(1,objname,"PDF") = 1 Then
        Cnt = Cnt + 1
    End If

Next

Msgbox "Total No. of Elements : = " & Cnt



RE: Count number of webelement with specific names - Ankesh - 07-31-2012

@ssvali : The code which you have posted will take much more time to execute and give the count coz it has to compare each element to check for PDF or XLS. Instead of this we can use regular expression which requires less time for execution.

Just update the line

Code:
Desc_Element("name").Value = ".*XLS.*"


with below line

Code:
Desc_Element("name").Value = ".*XLS.*|.*PDF.*"


Hope this will work for you.

Regards,
Ankesh