简体   繁体   English

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

[英]Find text of a childnode in a javatree in UFT

I am trying to get the text/label of a child node of a javatree NOT the index. 我正在尝试获取javatree的子节点的文本/标签,而不是索引。

How do i do that in UFT ? 我如何在UFT中做到这一点?

My Java tree is as below 我的Java树如下 在此处输入图片说明

Code that i have tried : 我尝试过的代码:

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

I have also tried using .GetColumnValue("#0;#1") but that also did not work 我也尝试使用.GetColumnValue("#0;#1")但这也没有用

Traversing JTree in UFT is complicated than it should be. 在UFT中遍历JTree非常复杂。 Here is what I did when I had to traverse through a 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

Useful links 有用的链接

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM