Is there a recommended or preferred way to navigate arbitrary Windows application treeviews?
Background, research and code…
I am automating a test of TreeView navigation in a circa 2014 native Windows application.
The app behaves similarly to how Windows File Explorer displays files and folders in its left-hand navigation panel.
My goal is to programatically navigate the tree without direct knowledge of the child element names in advance.
I know the parent and can find it. I’m not sure how to find the children.
For example, given only the “windows” folder, find and process the children “ASUS”, then “Shortcuts”, etc.:
c:\windows
|-- ASUS
| |-- Shortcuts
My first broad assumption is that the tree view is internally similar to nested web page elements in HTML (DOM tree): , ,
, etc.
I’ve tried a few possibilities, such as one I found on StackOverflow for a web app that does a findElement() for the parent, then does findElements() for the children.
My code is almost identical to the StackOverflow code, except for the “Windows” references.
WindowsTestObject wo2 = new WindowsTestObject('')
wo2.setLocatorStrategy(WindowsTestObject.LocatorStrategy.NAME)
wo2.setLocator('XYZ')
Windows.doubleClick(wo2) // This works! The tree under XYZ has many children that appear after double-clicking
WebElement parent = Windows.findElement(wo2);
println "Parent: " + parent.toString()
List<WebElement> treeItems = parent.findElements(By.xpath("*"))
println "TreeItems.size: " + treeItems.size()
treeItems.each {println it}
Here is the console output:
//> Parent: [[io.appium.java_client.windows.WindowsDriver, Capabilities: {appTopLevelWindow=8059e, javascriptEnabled=true, platform=WINDOWS, platformName=WINDOWS}] -> name: XYZ]
//> TreeItems.size: 1
//> treeItems.each({ -> ... })
//> [[[[io.appium.java_client.windows.WindowsDriver, Capabilities: {appTopLevelWindow=2305c8, javascriptEnabled=true, platform=WINDOWS, platformName=WINDOWS}] -> name: XYZ]] -> xpath: *]
I’m not sure this is even a good way to do it, but I’ve exhausted my scanty knowledge and Google skills.
My thoughts:
- Windows may not work quite the same as the WebUI
- Tree view elements appear nested in XPATH, but may not actually be
- Its possible the first findElement call for “parent” doesn’t refresh the page information with the newly opened tree after double-clicking
- I’m not sure how to get Spy to work since the app requires login, then switches Windows - native recorder works, but of course the results are static
Using the XPATH from the Object Repository doesn’t seem to fair any better, for example:
WebElement parent = Windows.findElement(By.xpath("/Window/Custom[1]/Custom[2]/TreeView[1]/TreeViewItem[1]/TreeViewItem[8]/Text[1]"));
This seems to work, but still no children are found, even though I know the XPATH for the children. such as:
"/Window/Custom[1]/Custom[2]/TreeView[1]/TreeViewItem[1]/TreeViewItem[8]/Text[1]/TreeViewItem[3]"));
Any suggestions are welcome.
If I missed a similar post, a pointer would be great!
Thanks,
Jim