Class: AX::Menu

Inherits:
Element show all
Defined in:
lib/ax/menu.rb

Overview

UI element representing a menu. Not much to it...

Instance Method Summary collapse

Methods inherited from Element

#==, #actions, #ancestor, #ancestry, #application, #attribute, #attributes, #blank?, #bounds, #children, #description, #initialize, #inspect, #inspect_subtree, #invalid?, #method_missing, #methods, #parameterized_attribute, #parameterized_attributes, #perform, #pid, #respond_to?, #screenshot, #search, #set, #size_of, #to_h, #to_point, #to_s, #type, #writable?

Methods included from Accessibility::PrettyPrinter

#pp_checkbox, #pp_children, #pp_enabled, #pp_focused, #pp_identifier, #pp_position

Constructor Details

This class inherits a constructor from AX::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class AX::Element

Instance Method Details

#item(filters = {}) { ... } ⇒ AX::Element

Search the menu for a menu_item that matches the given filters. The filters should be specified just as they would be when calling Element#search.

Parameters:

  • filters (Hash) (defaults to: {})

Yields:

  • Optional block used for search filtering

Returns:

Raises:



65
66
67
68
69
# File 'lib/ax/menu.rb', line 65

def item filters = {}, &block
  result = self.search :menu_item, filters, &block
  return result unless result.blank?
  raise Accessibility::SearchFailure.new(self, :menu_item, filters, &block)
end

#scroll_to(element)

This method returns an undefined value.

Scroll the menu until the given element, which must be in the menu is visible in the bounds of the menu. This method will also move the mouse pointer to the given element.

If you need to scroll an unknown number of units through a menu, you can just pass the element that you need visible and this method will scroll to it for you.

Examples:


click window.pop_up do
  menu = pop_up.menu
  menu.scroll_to menu.item(title: "Expensive Cake")
end

Parameters:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ax/menu.rb', line 26

def scroll_to element
  Mouse.move_to self.to_point

  # calculate which scroll arrow to move to
  fudge_factor = self.item.size.height * 0.1
  point = self.position
  size  = self.size
  point.x += size.width / 2
  point.y += if element.position.y > point.y
               size.height - fudge_factor
             else
               fudge_factor
             end

  # scroll until element is visible
  until NSContainsRect(self.bounds, element.bounds)
    Mouse.move_to point
  end

  start = Time.now
  until Time.now - start > 5
    # Sometimes the little arrow bars in menus covering
    # up the menu item and we have to move just a bit more.
    if self.application.element_at(Mouse.current_position) != element
      Mouse.move_to element.to_point
    else
      break
    end
  end
end