1

I am using WinAppDriver (using NUnit and C#) to test some legacy win32 Applications.

As I debug the tests, I reach certain points where I need to see a list of all child elements of the selected element. This will allow me to build the next step in the test.

I have tried using different FindElementsXXX methods, but have not found any that work. It seems that none have a wildcard search option.

Is there a syntax for XPath that will work in this situation? I have seen several XPath snippets that "should" work, but I get errors that the pattern is not supported.

Brad Bruce
  • 7,638
  • 3
  • 39
  • 60

3 Answers3

0

Yes, there is an XPath expression for that. Given x is a string for your XPath element, you need to append /* to it. Example: /bookstore is the element... /bookstore/* selects all its child elements. Reference here.

Grzegorz Górkiewicz
  • 4,496
  • 4
  • 22
  • 38
  • I'll give that a try when I get back to a Windows 10 box. (Stuck on Windows 7 at work) – Brad Bruce Jan 30 '17 at 14:31
  • Do you have an example? By element, do you mean "bookstore" i the automation ID or something else? I am trying to use your advice for testing a wpf app so it's nt a web page although the elements are WebElement type in winappd speak. – Ewan Feb 11 '19 at 16:36
0

Stupid driver. I had 8 patterns that wouldn't work. The error was indicating that the pattern wasn't supported.

I ran across this post Web Driver Issue 51 that indicated that some of the download links might be pointing to old versions. Yep! That was the problem. The correct download link (as of Jan 30, 2017 is v0.7-beta )

Brad Bruce
  • 7,638
  • 3
  • 39
  • 60
  • I ended up doing my own XML parsing of the page source. The only thing I cannot find is accessing sub-menus. I can get the top level menu, but the sub-menu items are missing from the page source. – Brad Bruce Feb 02 '17 at 11:46
0

XAML:

<ListBox x:Name="MyList">..</ListBox>

WinAppDriver Test:

var listBox = testSession.FindElementByAccessibilityId("MyList");
var comboBoxItems = listBox.FindElementsByClassName("ListBoxItem"); 

XPath: syntax functions

var comboBoxItems = listBox.FindElementByXPath("//ListBoxItem"); // ok

In a real world scenario I would use something like this. But it is not working on my side too:

var xPath = "//ListBox[@Name=\"MyList\"]//ListBoxItem[@IsSelected=\"True\"]";
listBox.FindElementByXPath(xPath);        // => not working
listBox.FindElementByXPath("//ListBox");  // => empty?
listBox.FindElementByXPath("//ListView"); // => empty?

The child elements of a ComboBox are a bit special. They are created after clicking on the combo and I found some open issues on that.

To debug I use Inspect.exe that is explained in this video and Immediate window in VS. The table helps a bit to find out that:

  • WPF => Inspect.exe => WinAppDriver
  • x:Name => AutomationId => FindElementByAccessibilityId(*)
  • Control type => LocalizedControlType => FindElementByClass(ToUpperCamelCase(*))
r2d2
  • 592
  • 5
  • 15