Class: Watir::Option

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

Overview

Returned by Container#option.

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, #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, #title, #to_s, #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, #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, #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

#clearObject

Clear option in multi-select list.

Raises:

  • (TypeError)

    when select list is not multi-select.



138
139
140
141
142
143
144
# File 'lib/watir-classic/input_elements.rb', line 138

def clear
  raise TypeError, "you can only clear multi-selects" unless select_list.multiple?

  perform_action do
    change_selected false if selected?
  end
end

#disabled?String, ...

Retrieve element’s disabled? from the OLE method.

Returns:

  • (String, Boolean, Fixnum)

    element’s “disabled?” attribute value. Return type depends of the attribute type.

  • (String)

    an empty String if the “disabled?” attribute does not exist.

See Also:



118
# File 'lib/watir-classic/input_elements.rb', line 118

attr_ole :disabled?

#labelString, ...

Retrieve element’s label from the OLE method.

Returns:

  • (String, Boolean, Fixnum)

    element’s “label” attribute value. Return type depends of the attribute type.

  • (String)

    an empty String if the “label” attribute does not exist.

See Also:



121
# File 'lib/watir-classic/input_elements.rb', line 121

attr_ole :label

#nameString, ...

Retrieve element’s name from the OLE method.

Returns:

  • (String, Boolean, Fixnum)

    element’s “name” attribute value. Return type depends of the attribute type.

  • (String)

    an empty String if the “name” attribute does not exist.

See Also:



119
# File 'lib/watir-classic/input_elements.rb', line 119

attr_ole :name

#selectObject

Select the option in its select list.



127
128
129
130
131
# File 'lib/watir-classic/input_elements.rb', line 127

def select
  perform_action do
    change_selected true unless selected?
  end
end

#selected?Boolean

Returns true when option is selected, false otherwise.

Returns:

  • (Boolean)

    true when option is selected, false otherwise.



148
149
150
151
# File 'lib/watir-classic/input_elements.rb', line 148

def selected?
  assert_exists
  ole_object.selected
end

#textObject

Text of the option.



154
155
156
157
# File 'lib/watir-classic/input_elements.rb', line 154

def text
  l = label
  l.empty? ? super : l rescue ''
end

#valueString, ...

Retrieve element’s value from the OLE method.

Returns:

  • (String, Boolean, Fixnum)

    element’s “value” attribute value. Return type depends of the attribute type.

  • (String)

    an empty String if the “value” attribute does not exist.

See Also:



120
# File 'lib/watir-classic/input_elements.rb', line 120

attr_ole :value