Sha256: bee49f53e0bbc334b929531a14a7e2996df6bc8a2322d6a35a340f77fa0cdac1

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

module RAutomation
  module Adapter
    module MsUia
      class ListItem < Control
        include WaitHelper
        include Locators

        #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
        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

        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

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

        def selected?
          UiaDll::get_is_selected(uia_element)
        end

        alias_method :exists?, :exist?

      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rautomation-0.8.0 lib/rautomation/adapter/ms_uia/list_item.rb
rautomation-0.7.3 lib/rautomation/adapter/ms_uia/list_item.rb
rautomation-0.7.2 lib/rautomation/adapter/ms_uia/list_item.rb
rautomation-0.7.1 lib/rautomation/adapter/ms_uia/list_item.rb
rautomation-0.7.0 lib/rautomation/adapter/ms_uia/list_item.rb