Class: Watir::ModalDialog

Inherits:
Object
  • Object
show all
Includes:
Container, PageContainer, Win32
Defined in:
lib/watir/modal_dialog.rb

Constant Summary

Constants included from Win32

Win32::FindWindowEx, Win32::GW_CHILD, Win32::GW_ENABLEDPOPUP, Win32::GW_HWNDFIRST, Win32::GW_HWNDLAST, Win32::GW_HWNDNEXT, Win32::GW_HWNDPREV, Win32::GW_MAX, Win32::GW_OWNER, Win32::GetUnknown, Win32::GetWindow, Win32::IsWindow, Win32::User32

Instance Attribute Summary

Attributes included from Container

#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed

Instance Method Summary collapse

Methods included from Win32

window_exists?

Methods included from PageContainer

#check_for_http_error, #contains_text, #enabled_popup, #html, #set_container, #show_frames, #text, #url

Methods included from Container

#area, #areas, #button, #buttons, #cell, #cells, #checkbox, #checkboxes, #dds, #divs, #dls, #dts, #element, #element_by_css, #elements, #ems, #file_field, #file_fields, #form, #forms, #frame, #frames, #hidden, #hiddens, #image, #images, #javascript_dialog, #labels, #link, #links, #lis, #locate_all_elements, #locate_input_element, #locate_tagged_element, #log, #map, #maps, #modal_dialog, #popup, #pres, #ps, #radio, #radios, #row, #rows, #select_list, #select_lists, #set_container, #show_all_objects, #spans, #strongs, #table, #tables, #text_field, #text_fields

Constructor Details

#initialize(container) ⇒ ModalDialog

Returns a new instance of ModalDialog.



13
14
15
16
# File 'lib/watir/modal_dialog.rb', line 13

def initialize(container)
  set_container container
  @modal = ::RAutomation::Window.new(:hwnd=>@container.hwnd).child(:class => 'Internet Explorer_TridentDlgFrame')
end

Instance Method Details

#active? ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/watir/modal_dialog.rb', line 65

def active?
  @modal.active?
end

#attach_command ⇒ Object



48
49
50
# File 'lib/watir/modal_dialog.rb', line 48

def attach_command
  "Watir::IE.find(:hwnd, #{@container.hwnd}).modal_dialog"
end

#close ⇒ Object



44
45
46
# File 'lib/watir/modal_dialog.rb', line 44

def close
  document.parentWindow.close
end

#document ⇒ Object



35
36
37
38
# File 'lib/watir/modal_dialog.rb', line 35

def document
  locate
  @document
end

#exists?(timeout = 5) ⇒ Boolean Also known as: exist?

When checking to see if the modal exists we give it some time to find it. So if it does see a modal it returns immediately, otherwise it waits and checks

Returns:

  • (Boolean)


71
72
73
74
75
76
77
# File 'lib/watir/modal_dialog.rb', line 71

def exists?(timeout=5)
  begin
    Watir::Wait.until(timeout) {@modal.exists?}
  rescue Watir::Wait::TimeoutError
  end
  return @modal.exists?
end

#hwnd ⇒ Object



61
62
63
# File 'lib/watir/modal_dialog.rb', line 61

def hwnd
  @modal.hwnd
end

#locate ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/watir/modal_dialog.rb', line 18

def locate
  intUnknown = 0
  begin
    Watir::until_with_timeout do
      intPointer = " " * 4 # will contain the int value of the IUnknown*
      GetUnknown.call(hwnd, intPointer)
      intArray = intPointer.unpack('L')
      intUnknown = intArray.first
      intUnknown > 0
    end
  rescue Wait::TimeoutError => e
    raise NoMatchingWindowFoundException,
      "Unable to attach to Modal Window after #{e.duration} seconds."
  end
  @document = WIN32OLE.connect_unknown(intUnknown)
end

#title ⇒ Object



40
41
42
# File 'lib/watir/modal_dialog.rb', line 40

def title
  document.title
end

#wait(no_sleep = false) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/watir/modal_dialog.rb', line 52

def wait(no_sleep=false)
  sleep 1
  if exists?
    # do nothing
  else
    @container.page_container.wait
  end
end