Class: Watir::Image

Inherits:
Element show all
Defined in:
lib/watir-classic/image.rb

Overview

This class is the means of accessing an image on a page. Normally a user would not need to create this object as it is returned by the Watir::Container#image method

many of the methods available to this object are inherited from the Element class

Constant Summary

Constants inherited from Element

Element::TO_S_SIZE

Instance Attribute Summary

Attributes inherited from Element

#container

Attributes included from Container

#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed

Instance Method Summary collapse

Methods inherited from Element

#<=>, #__ole_inner_elements, #activeObjectHighLightColor, #assert_enabled, #assert_exists, #attribute_value, #click, #click!, #create_event, #disabled?, #dispatch_event, #document, #double_click, #enabled?, #exists?, #fire_event, #flash, #focus, #focused?, #initialize, #inspect, #locate, #method_missing, #ole_object, #ole_object=, #parent, #right_click, #send_keys, #style, #tag_name, #text, #to_subtype, #type_keys, #typingspeed, #visible?

Methods included from DragAndDropHelper

#drag_and_drop_by, #drag_and_drop_on

Methods included from Container

#__ole_inner_elements, #alert, #locator_for, #modal_dialog, #set_container, support_element, #wait

Methods included from Exception

message_for_unable_to_locate

Methods included from ElementExtensions

#present?, #wait_until_present, #wait_while_present, #when_present

Constructor Details

This class inherits a constructor from Watir::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Watir::Element

Instance Method Details

#file_sizeObject

this method returns the filesize of the image, as an int



34
35
36
37
# File 'lib/watir-classic/image.rb', line 34

def file_size
  assert_exists
  @o.invoke("fileSize").to_i
end

#heightObject

returns the height in pixels of the image, as an int



46
47
48
49
# File 'lib/watir-classic/image.rb', line 46

def height
  assert_exists
  @o.invoke("height").to_i
end

#loaded?Boolean

This method attempts to find out if the image was actually loaded by the web browser. If the image was not loaded, the browser is unable to determine some of the properties. We look for these missing properties to see if the image is really there or not. If the Disk cache is full (tools menu -> Internet options -> Temporary Internet Files), it may produce incorrect responses.

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/watir-classic/image.rb', line 55

def loaded?
  assert_exists
  file_size != -1
end

#save(path) ⇒ Object

This method saves the image to the file path that is given. The path must be in windows format (c:\dirname\somename.gif). This method will not overwrite a previously existing image. If an image already exists at the given path then a dialog will be displayed prompting for overwrite. path - directory path and file name of where image should be saved



89
90
91
92
93
94
95
96
97
# File 'lib/watir-classic/image.rb', line 89

def save(path)
  @container.goto(src)
  begin
    fill_save_image_dialog(path)
    @container.document.execCommand("SaveAs")
  ensure
    @container.back
  end
end

#to_sObject

returns a string representation of the object



26
27
28
29
30
31
# File 'lib/watir-classic/image.rb', line 26

def to_s
  assert_exists
  r = string_creator
  r += image_string_creator
  return r.join("\n")
end

#widthObject

returns the width in pixels of the image, as an int



40
41
42
43
# File 'lib/watir-classic/image.rb', line 40

def width
  assert_exists
  @o.invoke("width").to_i
end