Class: Vapir::IE::ModalDialog

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

Instance Method Summary collapse

Instance Method Details

#click_button(button_text, options = {}) ⇒ Object



44
45
46
47
48
# File 'lib/vapir-ie/modal_dialog.rb', line 44

def click_button(button_text, options={})
  assert_exists
  options=handle_options(options, :timeout => ModalDialog::DEFAULT_TIMEOUT)
  @modal_window.click_child_button_try_for!(button_text, options[:timeout])
end

#closeObject



50
51
52
53
54
55
56
57
58
59
# File 'lib/vapir-ie/modal_dialog.rb', line 50

def close
  if (document=IE::ModalDialogDocument.new(self, :error => false, :timeout => 0)) && document.exists?
    document.close
  else
    @modal_window.send_close!
  end
  ::Waiter.try_for(ModalDialog::DEFAULT_TIMEOUT, :exception => Vapir::Exception::WindowException.new("The modal window failed to close")) do
    !exists?
  end
end

#documentObject



69
70
71
72
# File 'lib/vapir-ie/modal_dialog.rb', line 69

def document
  assert_exists
  IE::ModalDialogDocument.new(self)
end

#exists?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/vapir-ie/modal_dialog.rb', line 28

def exists?
  @modal_window && @modal_window.exists?
end

#hwndObject



61
62
63
64
# File 'lib/vapir-ie/modal_dialog.rb', line 61

def hwnd
  assert_exists
  @modal_window.hwnd
end

#locateObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vapir-ie/modal_dialog.rb', line 7

def locate
  @modal_window=@browser.win_window.enabled_popup || begin
    # IE9 modal dialogs aren't modal to the actual browser window. instead it creates some
    # other window with class_name="Alternate Modal Top Most" and makes the modal dialog modal 
    # to that thing instead. this has the same text (title) as the browser window but that 
    # is the only relationship I have found so far to the browser window. I'd like to use a
    # stronger relationship than that, but, it'll have to do. 
    matching_windows = WinWindow::All.select do |win|
      win.parent && win.parent.class_name == "Alternate Modal Top Most" && win.parent.text == @browser.win_window.text
    end
    case matching_windows.size
    when 0
      nil
    when 1
      matching_windows.first
    else
      raise Vapir::Exception::WindowException, "found multiple windows that looked like popups: #{matching_windows.inspect}"
    end
  end
end

#set_text_field(value) ⇒ Object



37
38
39
40
41
42
# File 'lib/vapir-ie/modal_dialog.rb', line 37

def set_text_field(value)
  assert_exists
  edit_field=@modal_window.children.detect{|child| child.class_name=='Edit'} || (raise "No Edit field in the popup!")
  edit_field.send_set_text!(value)
  value
end

#textObject



32
33
34
35
# File 'lib/vapir-ie/modal_dialog.rb', line 32

def text
  assert_exists
  @modal_window.children.select{|child| child.class_name.downcase=='static' && child.text!=''}.map{|c| c.text }.join(' ')
end

#win_windowObject



65
66
67
# File 'lib/vapir-ie/modal_dialog.rb', line 65

def win_window
  @modal_window
end