GithubHelp home page GithubHelp logo

lanicon / wpath Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tobyqin/wpath

0.0 1.0 0.0 81 KB

WPath is a library to select Windows UI automatin element like XPath.

License: MIT License

C# 100.00%

wpath's Introduction

NuGet

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.

Installation

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)

Examples:

/Group/Button

  • Find the first button under first group element.

//Button[@Name='Save']

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

/[@Name='TabContainer']/Button[2]

  • 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'

/Button[first()]

  • Find the first button under current node

/Button[last()]

  • Find the last button under current node

Usage

  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(); }
}

[WPath("/Button[first()]")]
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);

Tips:

  • 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.

wpath's People

Contributors

cicaday avatar tobyqin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.