class Uia::Element

Public Class Methods

new(element) click to toggle source
# File lib/uia/element.rb, line 16
def initialize(element)
  @element = element
  @default = lambda { [:unknown] }
end

Public Instance Methods

as(pattern) click to toggle source
# File lib/uia/element.rb, line 89
def as(pattern)
  raise UnsupportedPattern.new(pattern, patterns) unless patterns.include? pattern
  extend pattern.to_pattern_const
end
click() click to toggle source
# File lib/uia/element.rb, line 102
def click
  Library.click(@element)
  true
end
click_center() click to toggle source
# File lib/uia/element.rb, line 107
def click_center
  Library.click_center(@element)
  true
end
control_type() click to toggle source
# File lib/uia/element.rb, line 25
def control_type
  Library::Constants::ControlTypes.find(@default) { |_, v| v == @element.control_type_id }.first
end
drag(info) click to toggle source
# File lib/uia/element.rb, line 29
def drag(info)
  start_x, start_y = info[:start]
  end_x, end_y = info[:end]
  left, top = bounding_rectangle

  coords = [
      left + start_x,
      top + start_y,
      left + end_x,
      top + end_y
  ]

  until focused?
    focus
  end
  Library.drag *coords
end
filter(locator) click to toggle source
# File lib/uia/element.rb, line 85
def filter(locator)
  descendants.select { |e| e.locators_match? locator }
end
find(locator) click to toggle source
# File lib/uia/element.rb, line 56
def find(locator)
  find_child(@element, locator)
end
find_all(locator) click to toggle source
# File lib/uia/element.rb, line 60
def find_all(locator)
  find_children(@element, locator)
end
focus() click to toggle source
# File lib/uia/element.rb, line 112
def focus
  Library.focus(@element)
end
locators_match?(locator) click to toggle source
# File lib/uia/element.rb, line 64
def locators_match?(locator)
  locator.all? do |locator, value|
    case locator
      when :pattern
        case value
          when Array
            !(patterns & value).empty?
          else
            patterns.include? value
        end
      else
        case value
          when Array
            value.include? send(locator)
          else
            send(locator) == value
        end
    end
  end
end
patterns() click to toggle source
# File lib/uia/element.rb, line 98
def patterns
  @element.pattern_ids.map { |id| Library::Constants::Patterns.find(@default) { |_, v| v == id }.first }
end
refresh() click to toggle source
# File lib/uia/element.rb, line 51
def refresh
  Library.refresh @element
  self
end
send_keys(*keys) click to toggle source
# File lib/uia/element.rb, line 47
def send_keys(*keys)
  Library.send_keys @element, Keys.encode(keys)
end
with(control_types) click to toggle source
# File lib/uia/element.rb, line 94
def with(control_types)
  extend control_types.to_control_type
end