Micro Focus QTP (UFT) Forums
How to click all the links on page and verify respective contents - 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: How to click all the links on page and verify respective contents (/Thread-How-to-click-all-the-links-on-page-and-verify-respective-contents)



How to click all the links on page and verify respective contents - sudhirzpatil - 11-23-2010

Hi All,

I want to click all the available links on the page and verify recpective contents of te page.

For example in http://newtours.demoaut.com web application there are following links like Home, Flights, Hotels,Sign Off, Register.

When click on each link relative contents displayed . I want to verify them.

I used Descriptive programing to get the counts of No of links and name. But then how to click each link and verify the content displayed when clicked on that link.

Any Idea friends ?

Thanks

Sudhir


RE: How to click all the links on page and verify respective contents - KavitaPriyaCR - 11-23-2010

Hi

please find the below example
Code:
Set oDesc = Description.Create()
oDesc("html tag").Value = "A"
Set rc = Browser().Page().ChildObjects(oDesc)
num = rc.Count()

For i=0 to num-1
   tag = rc(i).GetROProperty("innertext")
   href = rc(i).GetROProperty("href")
   Reporter.ReportEvent 0, "Links in Page", "name: " & tag & ";    url: " & href
Next

If you want to click on the link...then inside the for loop you can write
rc(i).Click


RE: How to click all the links on page and verify respective contents - sudhirzpatil - 11-23-2010

Thanks kavitaPriya,

I used same script, but after clicking First link, it stopped and not proceed further without any error.
Also it's not clear in which order it will going to click , so how can i insert checkpoint with respect to that page ?


RE: How to click all the links on page and verify respective contents - KavitaPriyaCR - 11-23-2010

Yes i thought of telling you this.
Browser properties may change when you click on the links each time... please check this and let me know.


RE: How to click all the links on page and verify respective contents - sudhirzpatil - 11-23-2010

Hi KavitaPriya,

I tried it with following script.
Code:
Set oLinks = Description.Create
oLinks("micclass").value = "Link"
set objLinks = Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").ChildObjects(oLinks)
LinkCount = objLinks.Count
msgbox LinkCount
For i = 0 to LinkCount-1step 1
linkname=objLinks(i).getroproperty("name")
msgbox linkname,0,"Current link is"
objLinks(cint(i)).Click
next

But
I am getting following error.

The test run cannot continue due to an unrecoverable error.

General run error.
Line (9): "objLinks(cint(i)).Click". The test run cannot continue due to an unrecoverable error.


RE: How to click all the links on page and verify respective contents - KavitaPriyaCR - 11-24-2010

Hi
What i meant was, the browser property may be changing after click action, its not necessary to usecInt function here it seems.
For example in ur script
Code:
set objLinks = Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").ChildObjects(oLinks)
Browser property => "Welcome: Mercury Tours" may be changing after click action. Please use the object spy to verify this after clicking on the available links.


RE: How to click all the links on page and verify respective contents - sudhirzpatil - 11-28-2010

Hi Kavitapriya,
yes the pagename is different for diff link. Also some links have same name.I tried with Object spy but didnt find any property which will display ' page name' value of the link.

Will you pls suggest any workaround how to get page name of all available Links and click them ?
Thanks in advance.


RE: How to click all the links on page and verify respective contents - manishbhalshankar - 11-30-2010

Hi,

Try using class property for browser and page instead of the dynamic properties.


RE: How to click all the links on page and verify respective contents - deepaksporty - 05-19-2011

I think once you get the links for a page the get the url of every link using GetRoProperty and store it in an array. Now once you have the url the you navigate to that url. now for every url you can put your checks for the respective page.