Class: Watir::Frame

Inherits:
Object
  • Object
show all
Includes:
Container, PageContainer
Defined in:
lib/watir/frame.rb,
lib/watir/camel_case.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 PageContainer

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

Methods included from Win32

window_exists?

Methods included from Container

#area, #areas, #button, #buttons, #cell, #cells, #checkbox, #checkboxes, #dds, #divs, #dls, #dts, #element, #elements, #ems, #file_field, #file_fields, #form, #forms, #frame, #hidden, #hiddens, #image, #images, #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, #wait

Constructor Details

#initialize(container, how, what) ⇒ Frame

Returns a new instance of Frame.



43
44
45
46
47
48
49
# File 'lib/watir/frame.rb', line 43

def initialize(container, how, what)
  set_container container
  @how = how
  @what = what
  @o = locate
  copy_test_config container
end

Instance Method Details

#attach_commandObject



55
56
57
# File 'lib/watir/frame.rb', line 55

def attach_command
  @container.page_container.attach_command + ".frame(#{@how.inspect}, #{@what.inspect})".gsub('"','\'')
end

#documentObject Also known as: getDocument



51
52
53
# File 'lib/watir/frame.rb', line 51

def document
  @o.document
end

#locateObject

Find the frame denoted by how and what in the container and return its ole_object

Raises:

  • (UnknownFrameException)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/watir/frame.rb', line 7

def locate
  how = @how
  what = @what
  frames = @container.document.frames
  target = nil
  
  for i in 0..(frames.length - 1)
    this_frame = frames.item(i)
    case how
    when :index
      index = i + 1
      return this_frame if index == what
    when :name
      begin
        return this_frame if what.matches(this_frame.name)
      rescue # access denied?
      end
    when :id
      # We assume that pages contain frames or iframes, but not both.
      this_frame_tag = @container.document.getElementsByTagName("FRAME").item(i)
      return this_frame if this_frame_tag and what.matches(this_frame_tag.invoke("id"))
      this_iframe_tag = @container.document.getElementsByTagName("IFRAME").item(i)
      return this_frame if this_iframe_tag and what.matches(this_iframe_tag.invoke("id"))
    when :src
      this_frame_tag = @container.document.getElementsByTagName("FRAME").item(i)
      return this_frame if this_frame_tag and what.matches(this_frame_tag.src)
      this_iframe_tag = @container.document.getElementsByTagName("IFRAME").item(i) 
      return this_frame if this_iframe_tag and what.matches(this_iframe_tag.src)
    else
      raise ArgumentError, "Argument #{how} not supported"
    end
  end
  
  raise UnknownFrameException, "Unable to locate a frame with #{how.to_s} #{what}"
end