我正在尝试获取javatree的子节点的文本/标签,而不是索引。
我如何在UFT中做到这一点?
我尝试过的代码:
Dim itemsCount
Dim nodeName
Dim myText
Dim selectItem()
Dim ProgramName
ProgramName = "17030-3 Parameter, programming"
itemsCount = CInt(WpfWindow("Tech Tool").JavaWindow("Program_ECU").JavaTree("Program_Control_Unit").GetROProperty("items count"))
Redim selectItem(itemsCount)
Set objItem = WpfWindow("Tech Tool").JavaWindow("Program_ECU").JavaTree("Program_Control_Unit").Object
For i = 0 To itemsCount-1
'selectItem(i)=WpfWindow("Tech Tool").JavaWindow("Program_ECU").JavaTree("Program_Control_Unit").GetItem(i)
selectItem(i)=WpfWindow("Tech Tool").JavaWindow("Program_ECU").JavaTree("Program_Control_Unit").Select ("#0;#"&i)
If Trim(CStr(ProgramName)) = Trim(CStr(objItem.getItem(i))) Then
objItem.Select(i)
msgbox "Success"
End If
Next
我也尝试过使用.GetColumnValue("#0;#1")
,但那也没有用
答案 0 :(得分:0)
在UFT中遍历JTree非常复杂。这是我不得不遍历JTree时要做的事情
Set JTree = WpfWindow("Tech Tool").JavaWindow("Program_ECU").JavaTree("Program_Control_Unit").Object
'return how many nodes there are in the tree irrespective of their level
MsgBox JTree.getRowCount
Set JModel = JTree.getModel 'get jtree data model
Set JRoot = JModel.getRoot 'get root so that we can traverse the tree
Call JTreeWalk(JModel, JRoot)
'recursively traverse the jtree
Sub JTreeWalk(JModel, objNode)
ctr = JModel.getChildCount(objNode)
For i = 0 To ctr - 1
Set objChild = JModel.getChild(objNode, i)
If JModel.isLeaf(objChild) Then
Print vbTab & objChild.toString
Else
Print "~~ " & objChild.toString & " ~~"
End If
Call JTreeWalk(JModel, objChild)
Next
End Sub
有用的链接