Class: Watir::Image
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
Instance Attribute Summary
Attributes inherited from Element
Attributes included from Container
#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed
Instance Method Summary collapse
-
#file_size ⇒ Object
this method returns the filesize of the image, as an int.
-
#height ⇒ Object
returns the height in pixels of the image, as an int.
-
#loaded? ⇒ Boolean
This method attempts to find out if the image was actually loaded by the web browser.
-
#save(path) ⇒ Object
This method saves the image to the file path that is given.
-
#to_s ⇒ Object
returns a string representation of the object.
-
#width ⇒ Object
returns the width in pixels of the image, as an int.
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
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_size ⇒ Object
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 |
#height ⇒ Object
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.
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_s ⇒ Object
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 |
#width ⇒ Object
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 |