northwoodspd / uia

A ruby gem for interacting with automation elements in Windows
MIT License
17 stars 4 forks source link

Uia

The Uia gem is a low-level driver for interacting with Microsoft UIA elements in a Windows environment.

Installation

Add this line to your application's Gemfile:

gem 'uia'

And then execute:

$ bundle

Or install it yourself as:

$ gem install uia

Usage

Getting started with uia is easy. Simply require uia and then include the Uia module wherever you would like to use it.

require 'uia'

main_window = Uia.find_element id: 'MainFormWindow'

# returns all elements under main_window that are of control type button
main_window.find_all(control_type: :button)

# returns the values of every element that implements the ValuePattern
main_window.find_all(pattern: :value).map {|e| e.as :value}.map &:value

Finding Elements

You can locate elements based on the following criteria:

Element

The Element class is a representation of the AutomationElement class in Microsoft UIA. It is the object that is returned from the root Uia#find_element as well as the Element#find and Element#select methods.

Properties

Methods

as

The #as method will decorate the Element with the specific pattern that you would like to interact with.

button = Uia.find_element(id: /MainForm/).find(id: 'aboutButton').as :invoke
button.invoke

Patterns

Window

Decorates your Element with the following methods:

Value

Invoke

ExpandCollapse

Toggle

Table

Table::Row

TableItem

Selection

SelectionItem

Known bug

Crash with [BUG] Segmentation fault. Cause of this is ffi gem bug. Periodically the ffi team releases bad gem ffi/ffi#649 ffi/ffi#302. The conditional solution is described here

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request