class Watir::Option

Represents an option in a select list.

Public Instance Methods

clear() click to toggle source

Clears (i.e. toggles selected state) option.

@example

browser.select(id: "foo").options.first.clear
# File lib/watir-webdriver/elements/option.rb, line 34
def clear
  click if selected?
end
selected?() click to toggle source

Is this option selected?

@return [Boolean]

# File lib/watir-webdriver/elements/option.rb, line 44
def selected?
  assert_exists
  element_call { @element.selected? }
end
text() click to toggle source

Returns the text of option.

Note that the text is either one of the following respectively:

* label attribute
* text attribute
* inner element text

@return [String]

Calls superclass method Watir::Element#text
# File lib/watir-webdriver/elements/option.rb, line 60
def text
  # A little unintuitive - we'll return the 'label' or 'text' attribute if
  # they exist, otherwise the inner text of the element

  attribute = [:label, :text].find { |a| attribute? a }

  if attribute
    attribute_value(attribute)
  else
    super
  end
end