Micro Focus QTP (UFT) Forums
want to change index dynamically of WebTable object - 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: want to change index dynamically of WebTable object (/Thread-want-to-change-index-dynamically-of-WebTable-object)



want to change index dynamically of WebTable object - atanu - 05-03-2011

need a urgent help.

I am new to QTP.I am facing a problem about object identification in QTP.

When i add a standard checkpoint.
the code is generated like
Code:
Browser("Application").Page("Application").Frame("main_Frame").WebTable("Security").Check CheckPoint("Security")


QTP can identify the WebTable object uniquely using Ordinal Identifier Type - Index and it's value.
But when if any development on this application, value of Index of WebTables are changed.
So Check Points related to the webtable are failed.
So i have to modify Index value of webtables after every new deployment.
so is it possible to set the index dynamically or any other approach which can avoid this problem.

If possible Please let me know how to do that.

Thanks in Advance...


RE: want to change index dynamically of WebTable object - supputuri - 05-03-2011

Hi Atanu,

First thing is check and choose the properties that can identify the object unique in different builds/application versions.

Second option : dynamic handling of the index value of the webtable.
Code:
Dim intCounter : intCounter = 0
Browser("Application").Page("Application").Frame("main_Frame").WebTable("Security").SetToProperty "index", intCounter
Do Until Browser("Application").Page("Application").Frame("main_Frame").WebTable("Security").Exist = True
     intCounter = intCounter + 1
     Browser("Application").Page("Application").Frame("main_Frame").WebTable("Security").SetToProperty "index", intCounter
Loop
Please let me know if you need any information.


RE: want to change index dynamically of WebTable object - atanu - 05-04-2011

Hi supputuri,

First option is not possible in this application as there is no unique object properties.
Second option, When i execute this code,the loop condition is never true.
So loop is not stopped.


RE: want to change index dynamically of WebTable object - tdevick - 05-04-2011

Atanu,

Try using descriptive programming to find all of the web tables with name "Security". This code searches frame "main_frame" for all web tables with the name "Security". "children.count", in the code below, is the number of such tables found. Then you can loop through the tables found, one by one, and do whatever you want. Maybe this will do what you want or give you some more ideas on how to solve your problem.

Tim

Code:
oDesc=Description.Create
oDesc("micclass").Value="WebTable"
oDesc("Name").Value="Security"
set children=Browser("Application").Page("Application").Frame("main_Frame").ChildObjects(oDesc)
for i = 0 to children.count - 1
    'here you can use children(i) to get properties, etc. e.g., children(i).GetROProperty("abs_x")
    'or children(i).click, etc. whatever you want to do with the web table found
next i



RE: want to change index dynamically of WebTable object - atanu - 05-07-2011

Thanks both for your reply.It helps to find out the solution.
Now I have solved this problem by two ways

1> Using regular Expression and runtime object Property(Without changing the index)

The code is like this,

Code:
Set obj = Description.Create
    obj("micclass").Value = "WebTable"
    obj("html tag").Value = "TABLE"
    obj("inner text").Value = "Security CodeLedger Category.*"
    Set objCol =   Browser("Application").Page("Application").Frame("mainFrame").ChildObjects(obj)    
    runtimename= objCol(1).GetROProperty("name")
    runtimeabs_x=objCol(1).GetROProperty("x")
    Browser("Application").Page("Application").Frame("mainFrame").WebTable("Security Code").SetToProperty "name", runtimename
    Browser("Application").Page("Application").Frame("mainFrame").WebTable("Security Code").SetToProperty "x", runtimeabs_x
    Browser("Application").Page("Application").Frame("mainFrame").WebTable("Security Code" ).Check CheckPoint("Security Code")

2> Change the WebTable index dynamically

The code is like this,

Code:
Set obj = Description.Create
    obj ("micclass").Value = "WebTable"
    obj ("html tag").Value = "TABLE"
    obj ("innertext").Value = "Security CodeLedger Category.*"
    Set objCol =   Browser ("Application").Page("Application").Frame("mainFrame").ChildObjects(obj)  
      If  iCount <> 0 Then
           Set  table2use=objCol.item(iCount-1)
     Else
          Msgbox ( "cound not find the table")
      End If

HeaderTableIndex= GetQTPTableIndex (table2use)
dataTableIndex=headerTableIndex
Browser("Application").Page("Application").Frame("mainFrame").WebTable("index:=" & dataTableIndex).Check CheckPoint("Security Code")

Function GetQTPTableIndex(TableObj)
         On Error Resume Next
         Set TableObj = TableObj.Object
         On Error Goto 0

        srcIndex = TableObj.sourceIndex
        Set domDocument = TableObj.document.documentElement
        Set allTables= domDocument.getElementsByTagName("TABLE")
         i = 0
        For each table in allTables
           If table.sourceIndex = srcIndex Then
             GetQTPTableIndex = i
             Exit Function
          End If
        i = i + 1
       Next
End Function



RE: want to change index dynamically of WebTable object - anshikagoyal - 07-13-2012

I am very new to QTP and VB script

Can you please explain the logic you have applied inside the function GetQTPTableIndex in index method

Also what is purpose of below condition and from where is iCount coming?
Code:
If iCount <> 0 Then
Set table2use=objCol.item(iCount-1)
Else
Msgbox ( "cound not find the table")
End If

Thanks in advance!!