Micro Focus QTP (UFT) Forums
Get the ClassName of the cell object from a Table. - 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: Get the ClassName of the cell object from a Table. (/Thread-Get-the-ClassName-of-the-cell-object-from-a-Table)



Get the ClassName of the cell object from a Table. - guin.anirban - 09-24-2010

I want to get the Class Name of the cell Object from a table. Mean to say i want to return the class name whether it's a checkbox, editbox, list, button etc.


RE: Get the ClassName of the cell object from a Table. - QTPLearn - 09-24-2010

Hi
1st Approach:
Use 'ChildItem' method to get the class.
Code:
Set WebEditObj = Browser("Browser").Page("Page").WebTable("Sortable table").ChildItem(Row,Column,"WebEdit",0)



2nd Approach:
Use 'GetROProperty'.

Code:
strClassName = Browser("Browser").Page("Page").WebTable("Table").GetROProperty("Class")


~Regards


RE: Get the ClassName of the cell object from a Table. - guin.anirban - 09-24-2010

Thanks for your answer.

But i want to return the class of the cell object. In your 1st example you are clearly mentioned class as "WebEdit' and in the 2nd example will return "Table".


RE: Get the ClassName of the cell object from a Table. - A.Saini - 09-25-2010

Hi,

Actually "micclass" is the must entered property for "childobject" approch.And for the GetROproperty method it's mandatory to define the ClassType.

Normally we get the other property with the help of ClassType.So this case seems little strange.

May you please be more specific to your requirement?


RE: Get the ClassName of the cell object from a Table. - guin.anirban - 09-27-2010

The requirement is like i want to write a function for table that will return the Class Name of the particular cell if i pass the row and column number. Obviously if and only if that Class to that particular cell exists.


RE: Get the ClassName of the cell object from a Table. - guin.anirban - 09-29-2010

Hi Saket,

can you please help me on this query?


RE: Get the ClassName of the cell object from a Table. - guin.anirban - 10-08-2010

Hi All,

Is there any update on my query?


RE: Get the ClassName of the cell object from a Table. - A.Saini - 10-08-2010

Hi anirban,

Are you able to get the data of each cell using "GetCellData" method in this case???


RE: Get the ClassName of the cell object from a Table. - cdesserich - 10-08-2010

I think we are getting confused whether you want the micclass (QTP object type), the CSS class (the value of the element's class attribute), or the input type (the value of an input element's type attribute). Here is code to check each cell of a table and return several types of information about the first child of each cell. I assume you could customize it if you needed to check all the cell children and that you can remove the parts you aren't interested in. This code was tested with the attached HTML file (see attachment) after adding the table to the Object Repository and renaming it "Table". I do not think this code will work for nested tables, so beware. The reason is that the ChildObjects function returns child objects for any hierarchy so it would potentially return rows and columns nested inside the parent table if there are any, so again beware.

Quote:Set rowDesc = Description.Create
rowDesc("micclass").Value = "WebElement"
rowDesc("html tag").Value = "TR"

Set cellDesc = Description.Create
cellDesc("micclass").Value = "WebElement"
cellDesc("html tag").Value = "TD"

Set rows = Browser("Test").Page("Test").WebTable("Table").ChildObjects(rowDesc)

For i = 0 To rows.Count - 1

_____Dim cells: Set cells = rows.Item(i).ChildObjects(cellDesc)

_____For j = 0 To cells.Count - 1

__________Dim message: message = "Checking row " & i+1 & ", column " & j+1

__________Dim cellChildren: Set cellChildren = cells.Item(j).ChildObjects()

__________If cellChildren.Count > 0 Then

_______________Dim firstChild: Set firstChild = cells.Item(j).ChildObjects().Item(0)

_______________message = message & vbNewLine & vbNewLine & "Found " & cellChildren.Count & _
______________________________" child object(s). First child:" & vbNewLine & vbNewLine & _
______________________________"micclass: '" & firstChild.GetROProperty("micclass") & "'" & vbNewLine

_______________If firstChild.GetROProperty("html tag") = "INPUT" Then
____________________message = message & "input type: '" & firstChild.GetROProperty("type") & "'" & vbNewLine
_______________End If

_______________message = message & "css class: '" & firstChild.GetROProperty("class") & "'"

__________Else

_______________message = message & vbNewLine & vbNewLine & "Found no cell child objects. Cell text:" & vbNewLine & vbNewLine & _
______________________________"'" & cells.Item(j).GetROProperty("innertext") & "'"

__________End If

__________MsgBox message

_____Next

Next