WPath is a library to select Windows UI automatin element like XPath.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



WPath Introduction

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

Get Started

  1. The path should be started with '/'.
  2. Use '/' to separate element nodes in a path.
  3. The node name should be control type name, but it's optional.
  4. The UI element properties are treated as attribute in XPath.
  5. Supported attributes:
  • Name (NameProperty)
  • ID (AutomationIdProperty)
  • Class (ClassNameProperty)
  • Enabled (IsEnabledProperty)
  • FrameworkID (FrameworkIdProperty)



  • Find the first button under first group element.


  • Find a button with name "Save" in descendants.


  • Find the second button under an element named with 'TabContainer'

/Button[@ID='AddButton' and @Name='Add']

  • Find a button with automation ID 'AddButton' and name 'Add'

/Button[@ID='AddButton' or @Name='Add']

  • Find a button with automation ID 'AddButton' or name 'Add'


  • Find the first button under current node


  • Find the last button under current node


  1. Set WPath by attribute, works for C# function and property member.
[WPath("/Edit[@id='txtId' or @Class='TextBox']")]
public AutomationElement EditControl
   get { return this.AppElement.FindByWPath(); }

public AutomationElement GetFirstButton()
   return this.AppElement.FindByWPath();
  1. Call FindByWPath(path) method to locate the element
var 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);


  • The node name and attribute name is case insensitive
    • @name = @Name
    • /edit = /Edit
  • Welcome to extend the feature by sending pull requests.
  • Parent element locator ../ is not support yet.
  • For more usage please refer to unit test examples.