Brad Bruce
Brad Bruce

Reputation: 7827

How do I get a list of child elements using winappdriver in a win32 application?

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.

Upvotes: 2

Views: 9856

Answers (3)

r2d2
r2d2

Reputation: 637

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(*))

Upvotes: 0

Brad Bruce
Brad Bruce

Reputation: 7827

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 )

Upvotes: 0

Grzegorz G&#243;rkiewicz
Grzegorz G&#243;rkiewicz

Reputation: 4596

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.

Upvotes: 0

Related Questions