Class: Watir::Image

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

Overview

Returned by Container#image

Instance Attribute Summary

Attributes inherited from Element

#container

Attributes included from Container

#page_container

Instance Method Summary collapse

Methods inherited from Element

#<=>, #attribute_value, #class_name, #click, #disabled?, #double_click, #enabled?, #exists?, #fire_event, #flash, #focus, #focused?, #id, #initialize, #inner_html, #inspect, #method_missing, #ole_object, #outer_html, #parent, #right_click, #send_keys, #style, #tag_name, #text, #title, #to_subtype, #unique_number, #visible?

Methods included from DragAndDropHelper

#drag_and_drop_by, #drag_and_drop_on

Methods included from Container

#a, #abbr, #address, #alert, #area, #article, #aside, #audio, #b, #base, #bdi, #bdo, #blockquote, #body, #br, #button, #canvas, #caption, #checkbox, #cite, #code, #col, #colgroup, #command, #data, #datalist, #dd, #del, #details, #dfn, #div, #dl, #dt, #element, #em, #embed, #fieldset, #figcaption, #figure, #file_field, #font, #footer, #form, #frame, #frameset, #h1, #h2, #h3, #h4, #h5, #h6, #head, #header, #hgroup, #hidden, #hr, #i, #img, #input, #ins, #kbd, #keygen, #label, #legend, #li, #map, #mark, #menu, #meta, #meter, #modal_dialog, #nav, #noscript, #object, #ol, #optgroup, #option, #output, #p, #param, #pre, #progress, #q, #radio, #rp, #rt, #ruby, #s, #samp, #script, #section, #select, #small, #source, #span, #strong, #style, #sub, #summary, #sup, #table, #tbody, #td, #text_field, #textarea, #tfoot, #th, #thead, #time, #title, #tr, #track, #u, #ul, #var, #video, #wbr

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_sizeFixnum

Returns file size of the image in bytes.

Returns:

  • (Fixnum)

    file size of the image in bytes.



10
11
12
13
# File 'lib/watir-classic/image.rb', line 10

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

#heightFixnum

Returns height of the image in pixels.

Returns:

  • (Fixnum)

    height of the image in pixels.



24
25
26
27
# File 'lib/watir-classic/image.rb', line 24

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

#loaded?Boolean

Returns true if image is loaded by the browser, false otherwise.

Returns:

  • (Boolean)

    true if image is loaded by the browser, false otherwise.



31
32
33
34
# File 'lib/watir-classic/image.rb', line 31

def loaded?
  assert_exists
  file_size != -1
end

#save(path) ⇒ Object

TODO:

it should raise an Exception if image already exists.

Note:

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.

Save the image to the file.

Examples:

browser.image.save("c:/foo/bar.jpg")

Parameters:

  • path (String)

    path to the file.



48
49
50
51
52
53
54
55
56
# File 'lib/watir-classic/image.rb', line 48

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

#to_sObject



58
59
60
61
62
63
# File 'lib/watir-classic/image.rb', line 58

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

#widthFixnum

Returns width of the image in pixels.

Returns:

  • (Fixnum)

    width of the image in pixels.



17
18
19
20
# File 'lib/watir-classic/image.rb', line 17

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