Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get the ClassName of the cell object from a Table.
#9
Not Solved
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


Attached Files
.html   Test.html (Size: 1.62 KB / Downloads: 102)
Reply


Messages In This Thread
RE: Get the ClassName of the cell object from a Table. - by cdesserich - 10-08-2010, 11:29 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)