Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QTP DP to click no. of pages
#1
Solved: 10 Years, 8 Months, 4 Weeks ago
hi,
I have click on the page nos displayed in my search screen and for that i have written the below code but the problem is it clicks only on 2nd page and then qtp throws an "General Run error" when for loop gets executed for 2nd time.

Please let me know how to resolve the issue

Code:
Dim NumberOfLinks
Set oDesc = Description.Create()
oDesc("micclass").Value = "Link"
Set LinkCnt = Browser("Bro").Page("page").Webelement("elm_PageNos").ChildObjects(oDesc)
NumberOfLinks = LinkCnt.Count
For i = 0 To NumberOfLinks
     LinkCnt(i).highlight 1
    LinkCnt(i).Click
Next
Reply
#2
Solved: 10 Years, 8 Months, 4 Weeks ago
Hi,
Can you specify on which line this error is coming? Also you can check the proprties of 2nd page are matching with 1st page (the page on which you succesfuly clicked the link.)
Reply
#3
Solved: 10 Years, 8 Months, 4 Weeks ago
Error is displayed on line no 7 and 8 when value of i = 1.
Well as 1st page is displayed when a search is performed, i need not have to click on it and its property is an WebElement, only the pages which i need to clicked have Link property and once i click on 2nd page no it changes its property to WebElement and then i need to click on 3rd page no. and so on..


Attached Files Image(s)
   
Reply
#4
Solved: 10 Years, 8 Months, 4 Weeks ago
1. What does msgbox NumberOfLinks display ?
2. Is there a reason you have written LinkCnt(i).Highlight 1 instead of LinkCnt(i).Highlight ?
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, 8 Months, 4 Weeks ago
Ans1: - As per the attachment, NumberOfLinks = 3
Ans2: - No there no any particular reason
Note: Only line no 8 is throwing an General run error, where as when i = 1 its highlighting page no 3
Reply
#6
Solved: 10 Years, 8 Months, 4 Weeks ago
Hi,
You can try this out. This will go on till it finds the page count links.

Code:
Dim blnProceed, oLink, objTmp, LinkColl
blnProceed = True
i = 0
Do
        Set objTmp = Description.Create()
        objTmp("micclass").Value = "Link"
        objTmp("text").Value = Cstr(i + 2)
        Set LinkColl = Browser("Br").Page("Pg").ChildObjects(objTmp)
        If LinkColl.Count > 0 Then
            Set oLink = LinkColl(0)
            oLink.HighLight
            oLink.Click
            i = i + 1
        Else
            blnProceed = False
        End If
Loop While blnProceed
Reply
#7
Solved: 10 Years, 8 Months, 4 Weeks ago
Hi rashmi...

call the below line again to reload the object list again after clicking for the link for page number.

Code:
Set LinkCnt = Browser("Bro").Page("page").Webelement("elm_PageNos").ChildObjects(oDesc)


reason: qtp must identify objects again after page loading.previous page objects will be different from current one so u need to reload them again.
the solution manab provided will work .. since he is reloading the object list of links in a do while loop.
but it will start giving u prob if there are more page num links.

u can remove the object creation part from the loop.
Reply
#8
Solved: 10 Years, 8 Months, 4 Weeks ago
@Everyone - Please wrap your code using proper tags while replying. Read this.

Reply
#9
Solved: 10 Years, 8 Months, 4 Weeks ago
Hey Manoj,
Thanks a lot, it working perfectly fine, but i would be gald if you wud tell me the reason for which my code was giving a problem.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I can't displaying all the pages name in the .txt file njnirmal 9 4,647 08-17-2009, 05:56 PM
Last Post: manabh
  calling single script to identify web pages dynamically Anj 2 3,315 01-22-2008, 03:35 PM
Last Post: Anj

Forum Jump:


Users browsing this thread: 1 Guest(s)