Micro Focus QTP (UFT) Forums
QTP DP to click no. of pages - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: QTP DP to click no. of pages (/Thread-QTP-DP-to-click-no-of-pages)



QTP DP to click no. of pages - rashmi2309 - 09-03-2009

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



RE: QTP DP to click no. of pages - manabh - 09-03-2009

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.)


RE: QTP DP to click no. of pages - rashmi2309 - 09-03-2009

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..


RE: QTP DP to click no. of pages - basanth27 - 09-03-2009

1. What does msgbox NumberOfLinks display ?
2. Is there a reason you have written LinkCnt(i).Highlight 1 instead of LinkCnt(i).Highlight ?


RE: QTP DP to click no. of pages - rashmi2309 - 09-03-2009

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


RE: QTP DP to click no. of pages - manabh - 09-03-2009

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



RE: QTP DP to click no. of pages - satan - 09-03-2009

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.


RE: QTP DP to click no. of pages - Saket - 09-03-2009

@Everyone - Please wrap your code using proper tags while replying. Read this.


RE: QTP DP to click no. of pages - rashmi2309 - 09-03-2009

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.