Class: Watir::Option

Inherits:
HTMLElement show all
Defined in:
lib/watir-webdriver/elements/option.rb,
lib/watir-webdriver/elements/generated.rb

Overview

Represents an option in a select list.

Constant Summary

Constants included from Atoms

Atoms::ATOMS

Instance Method Summary collapse

Methods inherited from HTMLElement

#access_key, #access_key_label, #command_checked?, #command_disabled?, #command_hidden?, #command_icon, #command_label, #command_type, #content_editable, #content_editable?, #context_menu, #dataset, #dir, #draggable?, #dropzone, #hidden?, #item_id, #item_prop, #item_ref, #item_scope?, #item_type, #item_value, #lang, #onabort, #onautocomplete, #onautocompleteerror, #onblur, #oncancel, #oncanplay, #oncanplaythrough, #onchange, #onclick, #onclose, #oncontextmenu, #oncuechange, #ondblclick, #ondrag, #ondragend, #ondragenter, #ondragexit, #ondragleave, #ondragover, #ondragstart, #ondrop, #ondurationchange, #onemptied, #onended, #onerror, #onfocus, #oninput, #oninvalid, #onkeydown, #onkeypress, #onkeyup, #onload, #onloadeddata, #onloadedmetadata, #onloadstart, #onmousedown, #onmouseenter, #onmouseleave, #onmousemove, #onmouseout, #onmouseover, #onmouseup, #onmousewheel, #onpause, #onplay, #onplaying, #onprogress, #onratechange, #onreset, #onresize, #onscroll, #onseeked, #onseeking, #onselect, #onshow, #onsort, #onstalled, #onsubmit, #onsuspend, #ontimeupdate, #ontoggle, #onvolumechange, #onwaiting, #properties, #spellcheck?, #tab_index, #title, #translate?

Methods inherited from Element

#==, #attribute_value, #browser, #class_name, #click, #double_click, #drag_and_drop_by, #drag_and_drop_on, #driver, #exists?, #fire_event, #flash, #focus, #focused?, #hash, #hover, #id, #initialize, #inner_html, #inspect, #outer_html, #parent, #present?, #right_click, #run_checkers, #select_text, #send_keys, #style, #tag_name, #to_subtype, #visible?, #wd

Methods included from AttributeHelper

#attribute, #attribute_list, #inherit_attributes_from, #method, #typed_attributes

Methods included from EventuallyPresent

#wait_until_present, #wait_while_present, #when_present

Methods included from Container

#a, #abbr, #abbrs, #address, #addresses, #area, #areas, #article, #articles, #as, #aside, #asides, #audio, #audios, #b, #base, #bases, #bdi, #bdis, #bdo, #bdos, #blockquote, #blockquotes, #body, #bodys, #br, #brs, #bs, #button, #buttons, #canvas, #canvases, #caption, #captions, #checkbox, #checkboxes, #cite, #cites, #code, #codes, #col, #colgroup, #colgroups, #cols, #data, #datalist, #datalists, #datas, #dd, #dds, #del, #dels, #details, #detailses, #dfn, #dfns, #dialog, #dialogs, #div, #divs, #dl, #dls, #dt, #dts, #element, #elements, #em, #embed, #embeds, #ems, #extract_selector, #field_set, #field_sets, #fieldset, #fieldsets, #figcaption, #figcaptions, #figure, #figures, #file_field, #file_fields, #font, #fonts, #footer, #footers, #forms, #frame, #frames, #frameset, #framesets, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #head, #header, #headers, #heads, #hgroup, #hgroups, #hidden, #hiddens, #hr, #hrs, #html, #htmls, #i, #iframe, #iframes, #image, #images, #img, #imgs, #input, #inputs, #ins, #inses, #is, #kbd, #kbds, #keygen, #keygens, #labels, #legend, #legends, #li, #link, #links, #lis, #main, #mains, #map, #maps, #mark, #marks, #menu, #menuitem, #menuitems, #menus, #meta, #metas, #meter, #meters, #nav, #navs, #noscript, #noscripts, #object, #objects, #ol, #ols, #optgroup, #optgroups, #option, #options, #output, #outputs, #p, #param, #params, #pre, #pres, #progress, #progresses, #ps, #q, #qs, #radio, #radios, #rp, #rps, #rt, #rts, #rubies, #ruby, #s, #samp, #samps, #script, #scripts, #section, #sections, #select_list, #select_lists, #selects, #small, #smalls, #source, #sources, #span, #spans, #ss, #strong, #strongs, #style, #styles, #sub, #subs, #summaries, #summary, #sup, #sups, #table, #tables, #tbody, #tbodys, #td, #tds, #template, #templates, #text_field, #text_fields, #textarea, #textareas, #tfoot, #tfoots, #th, #thead, #theads, #ths, #time, #times, #title, #titles, #tr, #track, #tracks, #trs, #u, #ul, #uls, #us, #var, #vars, #video, #videos, #wbr, #wbrs

Methods included from Atoms

load

Methods included from XpathSupport

downcase, escape

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

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

Examples:

browser.select(:id => "foo").options.first.clear


35
36
37
# File 'lib/watir-webdriver/elements/option.rb', line 35

def clear
  click if selected?
end

#default_selected?Boolean

Returns value of defaultSelected property.

Returns:

  • (Boolean)

    value of defaultSelected property



372
# File 'lib/watir-webdriver/elements/generated.rb', line 372

attribute("Boolean", :default_selected?, :defaultSelected)

#disabled?Boolean

Returns value of disabled property.

Returns:

  • (Boolean)

    value of disabled property



369
# File 'lib/watir-webdriver/elements/generated.rb', line 369

attribute("Boolean", :disabled?, :disabled)

#formString

Returns value of form property.

Returns:

  • (String)

    value of form property



370
# File 'lib/watir-webdriver/elements/generated.rb', line 370

attribute(String, :form, :form)

#indexFixnum

Returns value of index property.

Returns:

  • (Fixnum)

    value of index property



375
# File 'lib/watir-webdriver/elements/generated.rb', line 375

attribute(Fixnum, :index, :index)

#labelString

Returns value of label property.

Returns:

  • (String)

    value of label property



371
# File 'lib/watir-webdriver/elements/generated.rb', line 371

attribute(String, :label, :label)

#selected?Boolean

Returns value of selected property.

Returns:

  • (Boolean)

    value of selected property



45
46
47
48
# File 'lib/watir-webdriver/elements/option.rb', line 45

def selected?
  assert_exists
  element_call { @element.selected? }
end

#textString

Returns the text of option.

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

* label attribute
* text attribute
* inner element text

Returns:

  • (String)


61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/watir-webdriver/elements/option.rb', line 61

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

#valueString

Returns value of value property.

Returns:

  • (String)

    value of value property



374
# File 'lib/watir-webdriver/elements/generated.rb', line 374

attribute(String, :value, :value)