Micro Focus QTP (UFT) Forums
Whether function can return number of links and their names in 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: UFT / QTP Interview Questions (https://www.learnqtp.com/forums/Forum-UFT-QTP-Interview-Questions)
+--- Thread: Whether function can return number of links and their names in a web page (/Thread-Whether-function-can-return-number-of-links-and-their-names-in-a-web-page)



Whether function can return number of links and their names in a web page - kotaramamohana - 06-27-2012

Hi Friends,

Whether function can return number of Links and their names in a web page. I have tried but I am getting error as "Wrong number of arguments or invalid property assignment"

Here is my code:
Code:
n=abc()

msgbox n.count

Public function abc()

Set linkdesc=description.Create
       linkdesc("micclass").value="Link"
Set objlink=browser("g").Page("g").ChildObjects(linkdesc)

  abc=objlink

End Function

Can you please share your ideas


RE: Whether function can return number of links and their names in a web page - ssvali - 06-27-2012

Try the below code

Code:
oval=  lnkCount()
For j = lbound(oval) to ubound(oval)
    Print oval(j)
Next
Print "Total No . of Link" &  ubound(oval)

Function lnkCount()

   Set linkDesc = Description.Create
    linkDesc("micclass").value = "Link"
    Set lnk = Browser("g").Page("g").ChildObjects(linkDesc)
    For i = 0 to lnk.Count - 1
        ReDim Preserve lnkname(i)
        lnkname(i) = lnk(i).GetROProperty("name")
        
    Next
    lnkCount = lnkname
    
End Function



RE: Whether function can return number of links and their names in a web page - kotaramamohana - 06-27-2012

Thanks Ssvali, Its working fine.


RE: Whether function can return number of links and their names in a web page - elango87 - 12-07-2012

Your approach is right.
Instead of using abc = objlink, you should have used
abc = objlink.count()

and in place of msgbox = n.count, you should use msgbox = n

below is the modified version of your code.

--
Code:
SystemUtil.Run "iexplore.exe", "google.com"
n=abc()

msgbox n

Public function abc()

Set linkdesc=description.Create
       linkdesc("micclass").value="Image"
Set objlink = Browser("Google").Page("Google").ChildObjects(linkdesc)
abc = objlink.Count()

End Function
--

hope this helps.

Thanks,
Elango