Micro Focus QTP (UFT) Forums
How to click on all links dynamically in UFT? - 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: How to click on all links dynamically in UFT? (/Thread-How-to-click-on-all-links-dynamically-in-UFT)



How to click on all links dynamically in UFT? - Rohan - 04-14-2011

Hi all,
i have written a script which will click on all the links in a page. the script is working fine for the first iteration while it is trying to click the second link in the page, a General Run Error is occurred. Go through the following script and correct me, suggest me.
Thanks.

Code:
set Links = Description.Create()
Links("micclass").Value = "Link"
set objLinks = Browser( "Google").Page( "Google").ChildObjects(Links)
LinkCount = objLinks.Count
msgbox LinkCount

For i = 1 To LinkCount-1
     objLinks(i).Click

Set obj1= createobject("wscript.shell")// Iam using this to navigate to
obj1.sendkeys "{TAB}"                     //previous page..
obj1.sendkeys "{BS}"
Next



RE: click on all links dynamically.. - Jay - 04-14-2011

try this :
Release every object, variable after first iteration.


RE: click on all links dynamically.. - Rohan - 04-14-2011

Thanks buddy, it worked.


click on all links dynamically.. - Rohan - 04-14-2011

This is exact code that works for any page in capturing all the link urls to the data table. By clicking on all the links dynamically.


Code:
Set oBrowser= Description.Create()
oBrowser("micclass").Value = "Browser"
set oPage = Description.Create()
oPage("micclass").Value = "page"

set Links = Description.Create()
Links("micclass").Value = "Link"
set objLinks = Browser( oBrowser).Page( oPage).ChildObjects(Links)
LinkCount = objLinks.Count
msgbox LinkCount


For i = 0 To LinkCount-1
set Links = Description.Create()
Links("micclass").Value = "Link"
set objLinks = Browser( oBrowser).Page( oPage).ChildObjects(Links)
  objLinks(i).Click
datatable.SetCurrentRow(i+1)
datatable("Lname",global)=Browser( oBrowser).Page( oPage).GetROProperty("href")
Browser(oBrowser).Back
set objLinks=nothing       
Next

Thanks all.


RE: click on all links dynamically.. - Meenakshi Sundar - 04-27-2011

Hi Rohan,
For your coding i am getting 'general Run error' error message.Can i know the reason? That too in the first part itself
Code:
Set oBrowser= Description.Create()
oBrowser("micclass").Value = "Browser"
set oPage = Description.Create()
oPage("micclass").Value = "page"

set Links = Description.Create()
Links("micclass").Value = "Link"
set objLinks = Browser( oBrowser).Page( oPage).ChildObjects(Links)
LinkCount = objLinks.Count
msgbox LinkCount



RE: click on all links dynamically.. - Jay - 04-27-2011

restart the QTP and then try....


RE: click on all links dynamically.. - Suhas Mitra - 01-24-2014


Hi,

Can anybody suggest me to find the number of links within the current page only. The codes that have been suggested will get the count of links in other pages also.

Thanks in advance


RE: click on all links dynamically.. - Anandkumar - 02-04-2016

Hi Rohan'

i am getting same issues,it was such as  General Run Error is occurred.please suggested me about script.

Thanks,
Anand.


RE: click on all links dynamically.. - sindhus - 02-22-2016

how to Release every object, variable after first iteration????


RE: click on all links dynamically.. - vinod123 - 02-25-2016

try the below code
Code:
Set Des_Obj = Description.Create
Des_Obj("micclass").Value = "Link"
Set link_col = Browser("micclass:=Browser").Page("micclass:=Page").ChildObjects(Des_Obj)
a = link_col.count
For i = 0 to a-1
tag = link_col(i).GetROProperty("name")
href = link_col(i).GetROProperty("url")
Browser("micclass:=Browser").Navigate href
Next