The Google Widget Toolkit (GWT) is a very popular and powerful toolkit, which is hard to test. The dynamic tree control is a very commonly used UI control in GWT. To expand the tree, we need to identify the Expand icon element.
You can find a sample dynamic GWT tree at http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwTree.
/BrowserApplication//BrowserWindow//DIV[@id='gwt-debug-cwTree-dynamicTree-root-child0']/DIV/DIV[1]//IMG[@border='0']
Often a good strategy for finding better locators is to search for siblings of elements that you need to locate. If you find siblings with better locators, XPath allows you to construct the locator by identifying those siblings. In this case, the tree item Item 0.0 provides a better locator than the Expand icon. The locator of the tree item Item 0.0 is a stable and simple locator as it uses the @textContents property of the control.
By default, Silk4J uses the property @id, but in GWT the @id is often not a stable property, because it contains a value like ='gwt-uid-<nnn>', where <nnn> changes frequently, even for the same element between different calls.
You can manually change the locator to use the @textContents property instead of the @id.
/BrowserApplication//BrowserWindow//DIV[@id='gwt-uid-109']
/BrowserApplication//BrowserWindow//DIV[@textContents='Item 0.0']
Or you can instruct Silk4J to avoid using @id='gwt-uid-<nnn>'. In this case Silk4J will automatically record the stable locator. You can do this by adding the text pattern that is used in @id properties to the locator attribute value blacklist. In this case, add gwt-uid* to the blacklist.
When inspecting the hierarchy of elements, you can see that the control Item 0.0 and the Expand icon control have a joint root node, which is a DomTableRow control.
/BrowserApplication//BrowserWindow//DIV[@textContent='Item 0.0']
/BrowserApplication//BrowserWindow//DIV[@textContent='Item 0.0']/../..//IMGOr even better, use the XPath ancestor axis to locate the Expand icon:
/BrowserApplication//BrowserWindow//DIV[@textContent='Item 0.0']/ancestor::tr//IMG