I need to find a value in Tree node in SAP

I need to find a value "Personnel number 60000357 invalid" in Tree node in SAP. Using UFT

' Get the SAPGuiTree object
Set tree = SAPGuiSession("Session").SAPGuiWindow("IDOC").SAPGuiTree("TreeControl")

' Start searching from the root node
i = 0

' Loop until a node is found or we run out of nodes
Do While True
' Try to get the node by index
On Error Resume Next
nodeKey = tree.GetNodeKeyByIndex("", i)
On Error GoTo 0

' If no nodeKey is found, exit the loop
If IsEmpty(nodeKey) Then
Exit Do
End If

' Expand the node to ensure any children are loaded
tree.Expand nodeKey

' Get the text of the current node
nodeText = tree.GetItemText(nodeKey)

' Check if this node's text contains "Purchase Order Completed"
If InStr(nodeText, "Personnel number 60000357 invalid") > 0 Then
found = True
tree.Select nodeKey
Exit Do
End If

' Move to the next node
i = i + 1
Loop

' Report the result
If found Then
Reporter.ReportEvent micPass, "Node Found", "The text 'Purchase Order Completed' was found in the tree."
Else
Reporter.ReportEvent micFail, "Node Not Found", "The text 'Purchase Order Completed' was not found in the tree."
End If

Not work above code.

  • Verified Answer

    +1  

    Hi,

    UFT don't provide methods like GetNodeKeyByIndex you used in the script, while you can use .Object to call native methods provided by SAP.

    Available methods can be found at SAP GUI Scripting API page 245

    Here is the script for reference:

    Set tree = SAPGuiSession("Session").SAPGuiWindow("Enjoy Demo Center: Display").SAPGuiTree("TableTreeControl")
    Set child=tree.Object.GetAllNodeKeys()
    For i = 0 To child.Count Step 1
        j= child.item(i)
        nodeText= tree.Object.GetNodeTextByKey(j)
        If InStr(nodeText, "SAP Easy Tree") > 0 Then
        found = True
        tree.Object.SelectNode(j)
        Exit For
        End If
    Next
    If found Then
    Reporter.ReportEvent micPass, "Node Found""The text 'Purchase Order Completed' was found in the tree."
    Else
    Reporter.ReportEvent micFail, "Node Not Found""The text 'Purchase Order Completed' was not found in the tree."
    End If

    Thanks,

    Mandy