简体   繁体   English

如何在Win32应用程序中使用winappdriver获得子元素的列表?

[英]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. 我正在使用WinAppDriver(使用NUnit和C#)测试某些旧版win32应用程序。

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. 我尝试使用其他FindElementsXXX方法,但未找到任何有效的方法。 It seems that none have a wildcard search option. 似乎没有一个通配符搜索选项。

Is there a syntax for XPath that will work in this situation? 在这种情况下,是否可以使用XPath的语法? I have seen several XPath snippets that "should" work, but I get errors that the pattern is not supported. 我已经看到了几个“应该”起作用的XPath代码段,但是却收到一些错误消息,提示该模式不支持。

Yes, there is an XPath expression for that. 是的,有一个XPath表达式。 Given x is a string for your XPath element, you need to append /* to it. 给定x是XPath元素的字符串,则需要在其后面附加/* Example: /bookstore is the element... /bookstore/* selects all its child elements. 示例: /bookstore是元素... /bookstore/*选择其所有子元素。 Reference here . 参考这里

Stupid driver. 愚蠢的司机。 I had 8 patterns that wouldn't work. 我有8种无效的模式。 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. 我遇到了这篇文章Web Driver Issue 51 ,该文章指出某些下载链接可能指向旧版本。 Yep! 是的! That was the problem. 那就是问题所在。 The correct download link (as of Jan 30, 2017 is v0.7-beta ) 正确的下载链接(截至2017年1月30日为v0.7-beta

XAML: XAML:

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

WinAppDriver Test: WinAppDriver测试:

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

XPath : syntax functions XPath语法 功能

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. ComboBox的子元素有些特殊。 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. 若要调试,请使用此视频中介绍的Inspect.exe和VS中的“立即”窗口。 The table helps a bit to find out that: 该表可以帮助您了解:

  • WPF => Inspect.exe => WinAppDriver WPF => Inspect.exe => WinAppDriver
  • x:Name => AutomationId => FindElementByAccessibilityId(*) x:名称=>自动化ID => FindElementByAccessibilityId(*)
  • Control type => LocalizedControlType => FindElementByClass(ToUpperCamelCase(*)) 控件类型=> LocalizedControlType => FindElementByClass(ToUpperCamelCase(*))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM