Micro Focus QTP (UFT) Forums

Full Version: How to click on all links dynamically in UFT?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
try this :
Release every object, variable after first iteration.
Thanks buddy, it worked.
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.
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
restart the QTP and then try....

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
Hi Rohan'

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

Thanks,
Anand.
how to Release every object, variable after first iteration????
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