Class: Watir::Table

Inherits:
HTMLElement show all
Includes:
Enumerable, RowContainer
Defined in:
lib/watir/elements/table.rb,
lib/watir/elements/html_elements.rb

Constant Summary

Constants inherited from Element

Element::CASE_INSENSITIVE_ATTRIBUTES

Instance Attribute Summary

Attributes inherited from Element

#keyword, #selector

Instance Method Summary collapse

Methods included from RowContainer

#row, #rows, #strings

Methods inherited from HTMLElement

#accesskey, #content_editable, #content_editable?, #dataset, #dir, #draggable?, #hidden?, #innertext, #lang, #onabort, #onblur, #oncancel, #oncanplay, #oncanplaythrough, #onchange, #onclick, #onclose, #oncopy, #oncuechange, #oncut, #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, #onpaste, #onpause, #onplay, #onplaying, #onprogress, #onratechange, #onreset, #onresize, #onscroll, #onseeked, #onseeking, #onselect, #onshow, #onstalled, #onsubmit, #onsuspend, #ontimeupdate, #ontoggle, #onvolumechange, #onwaiting, #onwheel, #spellcheck?, #tabindex, #title, #translate?

Methods inherited from Element

#==, #attribute_list, #attribute_value, #attribute_values, #browser, #build, #cache=, #center, #class_name, #classes, #click, #click!, #double_click, #double_click!, #drag_and_drop_by, #drag_and_drop_on, #driver, #enabled?, #focused?, #hash, #height, #hover, #id, #in_viewport?, #initialize, #inspect, #locate, #located?, #location, #obscured?, #present?, #reset!, #right_click, #selector_string, #send_keys, #set, #shadow_root, #size, #stale?, #stale_in_context?, #style, #tag_name, #text, #to_subtype, #wd, #width

Methods included from AttributeHelper

#attribute, #attribute_list, #define_attribute, #define_boolean_attribute, #define_float_attribute, #define_int_attribute, #define_string_attribute, #inherit_attributes_from, #method, #typed_attributes

Methods included from SearchContext

#assert_exists, #check_condition, #element_call, #exists?, #unknown_exception, #wait_for_exists

Methods included from Scrolling

#scroll

Methods included from Locators::ClassHelpers

#class_from_string, #element_class_name, #element_matcher_class, #locator, #locator_class, #selector_builder, #selector_builder_class

Methods included from JSExecution

#execute_script, #fire_event, #flash, #focus, #inner_html, #inner_text, #outer_html, #select_text, #selected_text, #text_content

Methods included from Adjacent

#child, #children, #following_sibling, #following_siblings, #parent, #preceding_sibling, #preceding_siblings, #siblings

Methods included from Waitable

#wait_until, #wait_while

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, #circle, #circles, #cite, #cites, #code, #codes, #col, #colgroup, #colgroups, #cols, #data, #datalist, #datalists, #datas, #date_field, #date_fields, #date_time_field, #date_time_fields, #dd, #dds, #defs, #defss, #del, #dels, #desc, #descs, #details, #detailses, #dfn, #dfns, #dialog, #dialogs, #div, #divs, #dl, #dls, #dt, #dts, #element, #elements, #ellipse, #ellipses, #em, #embed, #embeds, #ems, #field_set, #field_sets, #fieldset, #fieldsets, #figcaption, #figcaptions, #figure, #figures, #file_field, #file_fields, #font, #fonts, #footer, #footers, #foreign_object, #foreign_objects, #form, #forms, #frames, #frameset, #framesets, #g, #gs, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #head, #header, #heads, #hidden, #hiddens, #hr, #hrs, #html, #htmls, #i, #iframe, #iframes, #image, #images, #img, #imgs, #input, #inputs, #ins, #inses, #is, #kbd, #kbds, #label, #labels, #legend, #legends, #li, #line, #linear_gradient, #linear_gradients, #lines, #link, #links, #lis, #main, #mains, #map, #maps, #mark, #marker, #markers, #marks, #meta, #metadata, #metadatas, #metas, #meter, #meters, #nav, #navs, #noscript, #noscripts, #object, #objects, #ol, #ols, #optgroup, #optgroups, #option, #options, #output, #outputs, #p, #param, #params, #path, #paths, #pattern, #patterns, #picture, #pictures, #polygon, #polygons, #polyline, #polylines, #pre, #pres, #progress, #progresses, #ps, #q, #qs, #radial_gradient, #radial_gradients, #radio, #radio_set, #radios, #rb, #rbs, #rect, #rects, #rp, #rps, #rt, #rtc, #rtcs, #rts, #rubies, #ruby, #s, #samp, #samps, #script, #scripts, #section, #sections, #select, #select_list, #select_lists, #selects, #small, #smalls, #source, #sources, #span, #spans, #ss, #stop, #stops, #strong, #strongs, #style, #styles, #sub, #subs, #summaries, #sup, #sups, #svg, #svgs, #switch, #switches, #symbol, #symbols, #table, #tables, #tbody, #tbodys, #td, #tds, #template, #templates, #text_field, #text_fields, #text_path, #text_paths, #textarea, #textareas, #tfoot, #tfoots, #th, #thead, #theads, #ths, #time, #times, #title, #titles, #tr, #track, #tracks, #trs, #tspan, #tspans, #u, #ul, #uls, #us, #use, #uses, #var, #vars, #video, #videos, #view, #views, #wbr, #wbrs

Methods included from JSSnippets

#execute_js

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

#[](idx) ⇒ Object

Returns row of this table with given index.

Parameters:

  • idx (Integer)

Returns:

  • Watir::Row



59
60
61
# File 'lib/watir/elements/table.rb', line 59

def [](idx)
  row(index: idx)
end

#alignString

Returns value of align property.

Returns:

  • (String)

    value of align property



471
# File 'lib/watir/elements/html_elements.rb', line 471

attribute(String, :align, :align)

#bgcolorString

Returns value of bgColor property.

Returns:

  • (String)

    value of bgColor property



476
# File 'lib/watir/elements/html_elements.rb', line 476

attribute(String, :bgcolor, :bgColor)

#borderString

Returns value of border property.

Returns:

  • (String)

    value of border property



472
# File 'lib/watir/elements/html_elements.rb', line 472

attribute(String, :border, :border)

#cell_size_check(header_row, cell_row) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:



67
68
69
70
71
72
73
74
75
# File 'lib/watir/elements/table.rb', line 67

def cell_size_check(header_row, cell_row)
  header_size = header_row.cells.size
  row_size = cell_row.cells.size
  return if header_size == row_size

  index = cell_row.selector[:index]
  row_id = index ? "row at index #{index - 1}" : 'designated row'
  raise Error, "#{row_id} has #{row_size} cells, while header row has #{header_size}"
end

#cellpaddingString

Returns value of cellPadding property.

Returns:

  • (String)

    value of cellPadding property



477
# File 'lib/watir/elements/html_elements.rb', line 477

attribute(String, :cellpadding, :cellPadding)

#cellspacingString

Returns value of cellSpacing property.

Returns:

  • (String)

    value of cellSpacing property



478
# File 'lib/watir/elements/html_elements.rb', line 478

attribute(String, :cellspacing, :cellSpacing)

#each {|element| ... } ⇒ Object

Yields each TableRow associated with this table.

Examples:

table = browser.table
table.each do |row|
  puts row.text
end

Yield Parameters:



20
21
22
# File 'lib/watir/elements/table.rb', line 20

def each(&block)
  rows.each(&block)
end

#frameString

Returns value of frame property.

Returns:

  • (String)

    value of frame property



473
# File 'lib/watir/elements/html_elements.rb', line 473

attribute(String, :frame, :frame)

#hashesArray<Hash>

Represents table rows as hashes

Returns:

  • (Array<Hash>)


30
31
32
33
34
35
36
37
38
# File 'lib/watir/elements/table.rb', line 30

def hashes
  all_rows = rows.locate
  header_row = all_rows.first || raise(Error, 'no rows in table')

  all_rows.entries[1..].map do |row|
    cell_size_check(header_row, row)
    headers(header_row).map(&:text).zip(row.cells.map(&:text)).to_h
  end
end

#headers(row = nil) ⇒ TableCellCollection

Returns first row of Table with proper subtype

Returns:



46
47
48
49
50
# File 'lib/watir/elements/table.rb', line 46

def headers(row = nil)
  row ||= rows.first
  header_type = row.th.exist? ? 'th' : 'td'
  row.send("#{header_type}s")
end

#rulesString

Returns value of rules property.

Returns:

  • (String)

    value of rules property



474
# File 'lib/watir/elements/html_elements.rb', line 474

attribute(String, :rules, :rules)

#summaryString

Returns value of summary property.

Returns:

  • (String)

    value of summary property



475
# File 'lib/watir/elements/html_elements.rb', line 475

attribute(String, :summary, :summary)

#tbodiesString

Returns value of tBodies property.

Returns:

  • (String)

    value of tBodies property



470
# File 'lib/watir/elements/html_elements.rb', line 470

attribute(String, :tbodies, :tBodies)