Micro Focus QTP (UFT) Forums
Itereate through Link Items - 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: Itereate through Link Items (/Thread-Itereate-through-Link-Items)



Itereate through Link Items - lucster - 04-28-2011

Hey guys,

i am new to this board and the whole QTP.

With this code i iterate through links on a website:

Code:
i=0
j=1
While Browser("IDD Portal Login").Page("IDD Portal").Frame("frameLeft").Link("class:=arrow_normal", "html tag:=A", "index:="&i).Exists = true

    Datatable.SetCurrentRow (i+1)
    Browser("IDD Portal Login").Page("IDD Portal").Frame("frameLeft").Link("class:=arrow_normal", "html tag:=A", "index:="&i).Click
    i = i+1
    Wait 2

    While Browser("IDD Portal Login").Page("IDD Portal").Frame("frameMain").Link("class:=arrow_bold", "html tag:=A", "index:="&j).Exists = true

        txt = Browser("IDD Portal Login").Page("IDD Portal").Frame("frameMain").Link("class:=arrow_bold", "html tag:=A", "index:="&j).GetRoProperty("innertext")

        If txt <> "Instanz auswählen" Then
            print txt
            Datatable("Berichtstitel", dtGlobalsheet) = txt
        End If

        j = j+1
        
    Wend
    
Wend
Datatable.ExportSheet "D:\Daten\Berichtsl.xls", 1

As u may know now, the parser dont accept this, because the function EXISTS is not possible to use in that context.

Now i ask you, how i can define an end of my ieration? The count of iteration has to be variable. Anyone has an idea?

thanks in advance, lucster.


RE: Itereate through Link Items - vIns - 04-29-2011

Hi..
The above approach might NOT work as expected when you have only one link in the page. This is because, QTP uses index property only when multiple objects are found. When there is only one object, index property is simply ignored, so the above loop will repeat indefinitely. (even if you set index=10000, QTP's Exists property will return the value as True; but they all refer to same Link here)

So, Take the count first and proceed.

Code:
Set chObj = Description.Create
chObj("micclass").Value= "LINK"
chObj("html tag").Value ="A"
chObj("class").Value ="arrow_normal"

objCount = Browser("IDD Portal Login").Page("IDD Portal").ChildObjects(chObj).count



RE: Itereate through Link Items - lucster - 04-29-2011

This is how it works, your code needed some edit.


Code:
Set chObj1 = Description.Create
[b]'chObj1("micclass").Value= "LINK"[/b]
chObj1("html tag").Value ="A"
chObj1("class").Value ="arrow_normal"

objCount1 = Browser("IDD Portal Login").Page("IDD Portal")[b].Frame("frameLeft")[/b].ChildObjects(chObj1).count
Thanks for your help Smile