Class: RAutomation::Adapter::MsUia::ListItem

Inherits:
Control
  • Object
show all
Includes:
Locators, WaitHelper
Defined in:
lib/rautomation/adapter/ms_uia/list_item.rb

Instance Method Summary collapse

Methods inherited from Control

#assert_enabled, #bounding_rectangle, #click, #control_class, #control_name, #disabled?, #enabled?, #focus, #focused?, #get_current_control_type, #hwnd, #initialize, #matches_type?, #new_pid, #visible?

Constructor Details

This class inherits a constructor from RAutomation::Adapter::MsUia::Control

Instance Method Details

#exist?Boolean Also known as: exists?

Returns:

  • (Boolean)


36
37
38
# File 'lib/rautomation/adapter/ms_uia/list_item.rb', line 36

def exist?
  super && matches_type?(Constants::UIA_LIST_ITEM_CONTROL_TYPE)
end

#selected?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rautomation/adapter/ms_uia/list_item.rb', line 40

def selected?
  UiaDll::get_is_selected(uia_element)
end

#uia_element

Can’t get by value without a handle or a bug fix in the new way of getting a control by value so this is a workaround



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rautomation/adapter/ms_uia/list_item.rb', line 9

def uia_element
  if @locators[:value]
    uia_window = UiaDll::element_from_handle(@window.hwnd)
    begin
      uia_window.read_pointer
    rescue FFI::NullPointerError => e
      raise UnknownElementException, "Window with handle #{@window.hwnd} does not exist"
    end
    uia_control = UiaDll::find_child_by_name(uia_window, @locators[:value].to_s)
    begin
      uia_control.read_pointer
    rescue FFI::NullPointerError => e
      raise UnknownElementException, "#{@locators[:value]} does not exist"
    end
    uia_control
  else
    super
  end
end

#value



29
30
31
32
33
34
# File 'lib/rautomation/adapter/ms_uia/list_item.rb', line 29

def value
  list_item = uia_element
  item_value = FFI::MemoryPointer.new :char, UiaDll::get_name(list_item, nil) + 1
  UiaDll::get_name(list_item, item_value)
  item_value.read_string
end