Class: Vapir::IE::ModalDialogDocument

Inherits:
Object
  • Object
show all
Includes:
PageContainer
Defined in:
lib/vapir-ie/modal_dialog.rb

Constant Summary collapse

@@iedialog_file =
(File.expand_path(File.dirname(__FILE__) + '/..') + "/vapir-ie/IEDialog/Release/IEDialog.dll").gsub('/', '\\')

Constants included from PageContainer

PageContainer::READYSTATE_COMPLETE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PageContainer

#check_for_http_error, #close, #content_window_object, #execute_script, #html, #text, #wait

Methods included from Container

#handling_existence_failure, #log

Constructor Details

#initialize(containing_modal_dialog, options = {}) ⇒ ModalDialogDocument

Returns a new instance of ModalDialogDocument.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/vapir-ie/modal_dialog.rb', line 83

def initialize(containing_modal_dialog, options={})
  options=handle_options(options, :timeout => ModalDialog::DEFAULT_TIMEOUT, :error => true)
  @containing_modal_dialog=containing_modal_dialog
  
  intUnknown = nil
  ::Waiter.try_for(options[:timeout], :exception => (options[:error] && "Unable to attach to Modal Window after #{options[:timeout]} seconds.")) do
    intPointer = [0].pack("L") # will contain the int value of the IUnknown*
    get_unknown(@containing_modal_dialog.hwnd, intPointer)
    intArray = intPointer.unpack('L')
    intUnknown = intArray.first
    intUnknown > 0
  end
  if intUnknown && intUnknown > 0
    @document_object = WIN32OLE.connect_unknown(intUnknown)
  end
end

Instance Attribute Details

#containing_modal_dialogObject (readonly)

Returns the value of attribute containing_modal_dialog.



99
100
101
# File 'lib/vapir-ie/modal_dialog.rb', line 99

def containing_modal_dialog
  @containing_modal_dialog
end

#document_objectObject (readonly)

Returns the value of attribute document_object.



100
101
102
# File 'lib/vapir-ie/modal_dialog.rb', line 100

def document_object
  @document_object
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


105
106
107
108
# File 'lib/vapir-ie/modal_dialog.rb', line 105

def exists?
  # todo/fix: will the document object change / become invalid / need to be relocated? 
  @document_object && @containing_modal_dialog.exists?
end

#get_unknown(*args) ⇒ Object



78
79
80
81
82
# File 'lib/vapir-ie/modal_dialog.rb', line 78

def get_unknown(*args)
  require 'Win32API'
  @@get_unknown ||= Win32API.new(@@iedialog_file, 'GetUnknown', ['l', 'p'], 'v')
  @@get_unknown.call(*args)
end

#locate!(options = {}) ⇒ Object



101
102
103
# File 'lib/vapir-ie/modal_dialog.rb', line 101

def locate!(options={})
  exists? || raise(Vapir::Exception::WindowGoneException, "The modal dialog seems to have stopped existing.")
end

this looks for a modal dialog on this modal dialog. but really it’s modal to the same browser window that this is modal to, so we will check for the modal on the browser, see if it isn’t the same as our self, and return it if so.



113
114
115
116
117
118
119
120
# File 'lib/vapir-ie/modal_dialog.rb', line 113

def modal_dialog(options={})
  ::Waiter.try_for(ModalDialog::DEFAULT_TIMEOUT, 
                    :exception => NoMatchingWindowFoundException.new("No other modal dialog was found on the browser."),
                    :condition => proc{|md| md.hwnd != containing_modal_dialog.hwnd }
                  ) do
    modal_dialog=containing_modal_dialog.browser.modal_dialog(options)
  end
end