Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
click each web link in a page using Index or other method in QTP
#1
Solved: 10 Years, 9 Months ago
I have Browser("B").Page("P").Frame("body").Link("x").Click more that 10 on one page. I want to use for loop to click each links using the index or other method in QTP. Please help
Reply
#2
Solved: 10 Years, 9 Months ago
first use Child Objects to get the count of number of links a page.
And then use this count in the "for loop" to click on each of the links.
Reply
#3
Solved: 10 Years, 9 Months ago
Code:
Set oLinks = Description.Create
oLinks("micclass").value = "Link"
objLinks = Browser("B").Page("P").Frame("body").ChildObjects(oLinks)

LinkCount = objLinks.Count

For i = 0 to LinkCount-1

objLinks(cint(i)).Click

Next
Reply
#4
Solved: 10 Years, 9 Months ago
Modification :

objLinks(cint(i)).click - There is no requirment for Cint because we are dealing with HTML dom & there is no polymorphisim involved in this.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Reply
#5
Solved: 10 Years, 9 Months ago
Hi,

I need to click each and every link on a web page.
i tried the above mentioned option. since my web page is having many frames, it will select the links which we will specify in code.

How can i select all the frames in a web page and each time it should take the links in each frame and click it. after one frame over it should point to next frame and select all the links from that page.

Anybody could you please help me.
Reply
#6
Solved: 10 Years, 9 Months ago
Hi

Try this code

Code:
Set oFrame = Description.Create()
oFrame("micclass").Value =  "Frame"
Set oLinks = Description.Create()
oLinks("micclass").Value = "Link"
Set objFrame = Browser("B").Page("P").ChildObjects(oFrame)
FrameCount = objFrame.Count
If FrameCount > 0 Then
For i = 0 to FrameCount-1
  Set objLinks = Browser("B").Page("P").objFrame(i).ChildObjects(oLinks)
  LinkCount = objLinks.Count
  If LinkCount > 0 Then
      For k = 0 to LinkCount-1
objLinks(k).Click
Next
  Else
  Msgbox "Links Does not exist in Fame no "&k
  End If
Next
Else
Msgbox "Frame object does not exist"
End
Reply
#7
Solved: 10 Years, 9 Months ago
yup the above code will work's out. But, i think we have to come back to the same page after clicking on the link (if we are navigating to other page when clicked on link) under such conditions we have to use "Browser("B").Back" once we successfully clicked and navigated to other page.

Thanks,
QTPKing
Reply
#8
Solved: 10 Years, 9 Months ago
Hi all,

Thanks for the quick response. Its working fine.WinkWinkWinkWinkWink
Reply
#9
Solved: 10 Years, 9 Months ago
hi ,

In above program after each link clicked, as a effect of click on the links some time new web window will open and some time the Content of main page will change.

i need to check after clicking a link no error should be displayed in the web page


i used the below program to find whether any error occured in the web page. I called a program which will return false if any error occured in the page. then in main progrma i can write lik if error occured then just click on log off button so that it should lead to same page as it was before the occurance of error.

Here control is not going inside the statement--
If IsPageCannotBeDisplayed(oBrw,PCD_Keywords) Then

And also i am passing the argument oBrw as same all the time, how can i pass the web page name which is currently opened (it may be new Web page window or the same page where the data chanaged)

Below is the program where i changed

Bold letters are same as you mentioned in the above program

For k = 0 to LinkCount-1
objLinks(k).Click


Code:
Set oBrw = Browser("A").Page("B")
       If IsPageCannotBeDisplayed(oBrw,PCD_Keywords) Then
       Browser("A").Page("B").Frame      
        ("corner").Link("Log off").Click
       End If



Next




' Function which i am calling

Code:
Public Function IsPageCannotBeDisplayed (oBrw,PCD_Keywords)
    Dim  sUrl,sPageText,oPg

    IsPageCannotBeDisplayed = False

    If Not oBrw.Exist(0) Then

    Exit Function
    End If

    'Get the page object
    Set oPg = oBrw.Page("micclass:=Page")

    'A page might not exist when the dialog modal is present
    'in the browser
    If Not oPg.Exist(0) Then
    Exit Function
    End If


    sURL = oBrw.Page("micclass:=Page").GetROProperty("URL")

    'Special check for IE and FF URL checks
    If InStr(1,sURL,"shdoclc.dll",vbTextCompare) <> 0 Or InStr(1,sURL,"about:neterror?",vbTextCompare) <> 0 Then
        IsPageCannotBeDisplayed = True

    'IF IE then we will use HTML DOM to get the whole page text
    ElseIf InStr(1,oBrw.GetROProperty("version"),"internet explorer",vbTextCompare) Then
        sPageText = oPg.Object.documentElement.outerText
    End If

    Dim  sKeyword

    For Each sKeyword In PCD_Keywords
        'Check if our keyword exist on the page
        If InStr(1,sPageText,sKeyword,vbTextCompare) Then
            IsPageCannotBeDisplayed = True
            Exit Function
        End If
    Next
End Function

Dim  PCD_Keywords
PCD_Keywords = Array("The page cannot be displayed","Sorry page is not found","error")
Reply
#10
Solved: 10 Years, 9 Months ago
hi all,

in above post wat i meant to convey is--

After i click a link, new page is opening(in same window or new pop up window), i need to check that content of page should not be "Page cannot be displayed" or some "error message".

to achive this requirement i called the program which i have mentioned in the previous post. but it is not working properly,

Could you please guide me where i am going wrong.

and also for this function i need to pass the web page name which is recently opened as a effect of click on the link.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Webtable contains cell contains two links, how to click on link srinivassure 9 52,688 07-30-2016, 03:41 PM
Last Post: Akshay
  VB Script to count number of links in a web page. Suma Parimal 4 24,747 07-01-2015, 12:59 PM
Last Post: govind
  Upgraded QTP 11.0 to UFT 11.53, Object Index Properties are varying Raghava M 0 2,071 01-28-2015, 06:02 PM
Last Post: Raghava M
  General run error. Line (18): "Loop while Browser("Index:=0").Object.Busy" AshokReddy 3 4,786 12-20-2013, 01:44 PM
Last Post: sshukla12
  Unable to select a combo item by value or index martinshort 2 3,166 08-26-2013, 07:55 PM
Last Post: sudhirzpatil

Forum Jump:


Users browsing this thread: 1 Guest(s)