To access items in a SAP GUI GuiTree object, most methods need a key which identifies the node. To get such a key, you need the function findNodeKeyByPath()
. The description says:
Return the node key for the given path (e.g. 2\1\2).
path The node path. STRING.
I need to get the first child of the first item in the tree. Using "0"
throws an exception. Indexes of the root element seem to start at 1 instead of 0. Using "1"
and "2"
gives me correct keys.
But anything I try with a backslash does not work. "1\0"
does not throw an exception, neither does "1\1"
. But both parameters return the key of node "1"
and not of a subnode.
How do I need to construct the path in SilkTest (Silk4J, SAP) to get a valid key?
In Java, "\1"
is the octal representation of ASCII character 0x01. See What does \1 represent. The string "1\\1"
gives a valid path and returns the correct key.
However, the node must be visible, otherwise an empty string is returned. That means, you need the following code:
SapTree tree = ...; // initialize somewhere
String parentKey = tree.findNodeKeyByPath("1");
tree.expandNode(parentKey);
String key = tree.findNodeKeyByPath("1\\1");