在UFT中的javatree中查找子节点的文本

时间:2018-07-25 13:56:37

标签: automation hp-uft

我正在尝试获取javatree的子节点的文本/标签,而不是索引。

我如何在UFT中做到这一点?

我的Java树如下 enter image description here

我尝试过的代码:

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"),但那也没有用

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

有用的链接

  1. https://docs.oracle.com/javase/tutorial/uiswing/components/tree.html
  2. http://www.rgagnon.com/javadetails/java-0313.html(我使用此Java代码并将其转换为vbs)