Micro Focus QTP (UFT) Forums
Finding a Link - 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: Finding a Link (/Thread-Finding-a-Link)



Finding a Link - mv8167 - 06-20-2011

I am trying to find links on a web page. The attached pdf shows the code I have and the table that the code is using to fiind the Links. I tried using just the href of the Link object. Currently, my code is trying to use the Link properties for the name and href coulmns of the table. Can someone help me look mover why my code does not work.

My code:
Code:
For r = 2 to rNumber ' loop thru your DocView values (from 2 to rNumber or set to #)
    'DocView
    ReportType = ObjExcel.Cells(r,3)
    'Href
    Hreff = ObjExcel.Cells(r,4)
    
Browser("Wisdom").Page("Wisdom IA_2").Frame("parent_2").Link("href:="&Hreff; "name:="ReportType).Click



RE: Finding a Link - parminderdhiman84 - 06-20-2011

Hi,

Please try using below code:

Code:
For r = 2 to rNumber
    'DocView
    ReportType = ObjExcel.Cells(r,3)
    'Href
    Hreff = ObjExcel.Cells(r,4)
Browser("Wisdom").Page("Wisdom IA_2").Frame("parent_2").Link("href:="&Hreff,"name:="&ReportType).Click
Next

Regards,
Parminder


RE: Finding a Link - mv8167 - 06-20-2011

Parminder,

Thx, but nope the change still gave me the same error message.

The script sees the link, but the code fails. (see attachment)

The funny thing is that I create my dataTable using the page that I am currently trying to select the Lnk objects on. Can I somehow reuse this cose to help selecrt the links?
Code:
Set TableObj = Browser("Wisdom").Page("Wisdom IA_2").Frame("parent").WebTable("Select All")

Set LinkObj = TableObj.ChildItem(r, c, "Link", k)
LinkName = LinkObj.GetROProperty("innerText")
LinkHref = LinkObj.GetROProperty("href")

LinkName  = objExcel.Cells(rNumber, 3).Value
LinkHreff = objExcel.Cells(rNumber, 4).Value



RE: Finding a Link - parminderdhiman84 - 06-21-2011

Hi Lorena,

Please see if below approach helps you:

Code:
For r = 2 to rNumber
'DocView
ReportType = ObjExcel.Cells(r,3)
'Href
Hreff = ObjExcel.Cells(r,4)
href_app=Browser("Wisdom").Page("Wisdom IA_2").Frame("parent").WebTable("Select All").ChildItem(r,4,"Link",0).GetROProperty("href")  'Use this approach if elements in the application are in same order as in the excel file otherwise use another loop For loop for table
name_app=Browser("Wisdom").Page("Wisdom IA_2").Frame("parent").WebTable("Select All").ChildItem(r,4,"Link",0).GetROProperty("innertext")

If href_app= Hreff and name_app=ReportType Then
    Browser("Wisdom").Page("Wisdom IA_2").Frame("parent").WebTable("Select All").ChildItem(r,2,"Link",0).Click
    Else
    Reporter.ReportEvent micFail, "Link is not present at appropriate position","Step Failed"
End If

Next

I doubt the way you are looping through excel because for looping through excel is done using "Usedrange".

An alternate way can be by importing the excel file into global sheet in qtp and then running the loop on datatable.

Regards,
Parminder


RE: Finding a Link - mv8167 - 06-21-2011

Parminder

Thx for this most helpful responce. I will try this in the near future.

I was running out of time, so I went a different route. I dont think I can use the href propertie as I thought I should be able to (copy/paste). I find the href property in the table, copy the href property, but on saying find and use it, nope.

I ended up using the abs_x and abs_y. Since I import the object properties on each run, I can easily get the x-y cord for each link. The only property other than the href that is different for each link are the abs locations. So, if buttons move, I will still find them and use there new locations. Works great.

When I have a moment, I will try your idea. Thx for being so kind and helpful.