WPath is a library to select Windows UI automatin element like XPath.
WPath is a library to select Windows UI automation element like XPath. The WPath looks like XPath which was wildly using to select xml elements, but it is not exactly equal to XPath, it is being used to locate Microsoft UIAutomation elements. Some special rules list below.
You can clone the repository and compile source code by yourself. Or just install via nuget packages.
PM> Install-Package WPath
Name
(NameProperty)ID
(AutomationIdProperty)Class
(ClassNameProperty)Enabled
(IsEnabledProperty)FrameworkID
(FrameworkIdProperty)
/Group/Button
//Button[@Name='Save']
/[@Name='TabContainer']/Button[2]
/Button[@ID='AddButton' and @Name='Add']
/Button[@ID='AddButton' or @Name='Add']
/Button[first()]
/Button[last()]
[WPath("/Edit[@id='txtId' or @Class='TextBox']")]
public AutomationElement EditControl
{
get { return this.AppElement.FindByWPath(); }
}
[WPath("/Button[first()]")]
public AutomationElement GetFirstButton()
{
return this.AppElement.FindByWPath();
}
FindByWPath(path)
method to locate the elementvar path = "/Edit[3]";
var e = this.AppElement.FindByWPath(path);
Assert.AreEqual("txtKey", e.Current.AutomationId);
Assert.AreEqual(ControlType.Edit, e.Current.ControlType);
path = "/Button[@name='OK']/Text[1]";
e = this.AppElement.FindByWPath(path);
Assert.AreEqual("OK", e.Current.Name);
Assert.AreEqual(ControlType.Text, e.Current.ControlType);
../
is not support yet.