Module: Celerity::Container
- Includes:
- Celerity::Exception, Celerity::ShortInspect
- Defined in:
- lib/celerity/container.rb,
lib/celerity/watir_compatibility.rb
Overview
This class contains methods for accessing elements inside a container, usually the Browser object, meaning the current page. The most common syntax is
browser.elem(:attribute, 'value')
Note that the element is located lazily, so no exceptions will be raised if the element doesn’t exist until you call a method on the resulting object. To do this you would normally use Element#exists? or an action method, like ClickableElement#click. You can also pass in a hash:
browser.link(:index => 1).click
All elements support multiple attributes identification using the hash syntax (though this might not always be compatible with Watir):
browser.span(:class_name => 'product', :index => 5).text
Checkboxes and radio buttons support a special three-argument syntax:
browser.check_box(:name, 'a_name', '1234').set
You can also get all the elements of a certain type by using the plural form (@see Celerity::ElementCollection):
browser.links # => #<Celerity::Links:0x7a1c2da2 ...>
Attribute Summary
- - (Object) browser readonly Points back to the Browser instance that contains this element.
Method Summary
- - (Celerity::Area) area(*args)
- - (Celerity::Areas) areas
- - (Celerity::Button) button(*args)
- - (Celerity::Buttons) buttons
- - (Celerity::TableCell) cell(*args) (also: #td)
- - (Celerity::TableCells) cells (also: #tds)
- - (Celerity::CheckBox) check_box(*args) (also: #checkBox, #checkbox) Since finding checkboxes by value is very common, you can use this shorthand:.
- - (Celerity::CheckBoxes) checkboxes
- - (Object) container=(container) Used internally to update the container object.
- - (Fixnum) contains_text(expected_text) Check if the element contains the given text.
- - (Celerity::Dd) dd(*args)
- - (Celerity::Dds) dds
- - (Celerity::Div) div(*args)
- - (Celerity::Divs) divs
- - (Celerity::Dl) dl(*args)
- - (Celerity::Dls) dls
- - (Celerity::Dt) dt(*args)
- - (Celerity::Dts) dts
- - (Celerity::Em) em(*args)
- - (Celerity::Ems) ems
- - (Celerity::FileField) file_field(*args)
- - (Celerity::FileFields) file_fields
- - (Celerity::Form) form(*args)
- - (Celerity::Forms) forms
- - (Celerity::Frame) frame(*args)
- - (Celerity::Frames) frames
- - (Celerity::H1) h1(*args)
- - (Celerity::H1s) h1s
- - (Celerity::H2) h2(*args)
- - (Celerity::H2s) h2s
- - (Celerity::H3) h3(*args)
- - (Celerity::H3s) h3s
- - (Celerity::H4) h4(*args)
- - (Celerity::H4s) h4s
- - (Celerity::H5) h5(*args)
- - (Celerity::H5s) h5s
- - (Celerity::H6) h6(*args)
- - (Celerity::H6s) h6s
- - (Celerity::Hidden) hidden(*args)
- - (Celerity::Hiddens) hiddens
- - (Celerity::Image) image(*args)
- - (Celerity::Images) images
- - (Object) inspect Override inspect for readability.
- - (Celerity::Label) label(*args)
- - (Celerity::Labels) labels
- - (Celerity::Li) li(*args)
- - (Celerity::Link) link(*args)
- - (Celerity::Links) links
- - (Celerity::Lis) lis
- - (Celerity::Map) map(*args)
- - (Celerity::Maps) maps
- - (Celerity::Meta) meta(*args)
- - (Celerity::Metas) metas(*args)
- - (Celerity::Ol) ol(*args)
- - (Celerity::Ols) ols
- - (Celerity::Option) option(*args)
- - (Celerity::P) p(*args)
- - (Celerity::Pre) pre(*args)
- - (Celerity::Pres) pres
- - (Celerity::Ps) ps
- - (Celerity::Radio) radio(*args) Since finding radios by value is very common, you can use this shorthand:.
- - (Celerity::Radios) radios
- - (Celerity::TableRow) row(*args)
- - (Celerity::TableRows) rows
- - (Celerity::SelectList) select_list(*args)
- - (Celerity::SelectLists) select_lists
- - (Celerity::Span) span(*args)
- - (Celerity::Spans) spans
- - (Celerity::Spans) strong(*args)
- - (Celerity::Strongs) strongs
- - (Celerity::Table) table(*args)
- - (Celerity::Tables) tables
- - (Celerity::TableBodies) tbodies (also: #bodies)
- - (Celerity::TableBody) tbody(*args) (also: #body)
- - (Celerity::TextField) text_field(*args)
- - (Celerity::TextFields) text_fields
- - (Celerity::TableFooter) tfoot(*args)
- - (Celerity::TableFooters) tfoots (also: #tfeet)
-
- (Celerity::Th) th(*args)
Watir’s cells() won’t find
elements. - - (Celerity::TableHeader) thead(*args)
- - (Celerity::TableHeaders) theads
- - (Object) ths FIXME: implement or change api,.
- - (Celerity::Ul) ul(*args)
- - (Celerity::Uls) uls
Methods included from Celerity::ShortInspect
Attribute Details
- (Object) browser (readonly)
Points back to the Browser instance that contains this element
36 37 38
# File 'lib/celerity/container.rb', line 36 def browser @browser end
Method Details
- (Celerity::Area) area(*args)
86 87 88
# File 'lib/celerity/container.rb', line 86 def area(*args) Area.new(self, *args) end
- (Celerity::Areas) areas
94 95 96
# File 'lib/celerity/container.rb', line 94 def areas Areas.new(self) end
- (Celerity::Button) button(*args)
102 103 104
# File 'lib/celerity/container.rb', line 102 def (*args) Button.new(self, *args) end
- (Celerity::Buttons) buttons
110 111 112
# File 'lib/celerity/container.rb', line 110 def Buttons.new(self) end
- (Celerity::TableCell) cell(*args) Also known as: td
118 119 120
# File 'lib/celerity/container.rb', line 118 def cell(*args) TableCell.new(self, *args) end
- (Celerity::TableCells) cells Also known as: tds
127 128 129
# File 'lib/celerity/container.rb', line 127 def cells TableCells.new(self) end
- (Celerity::CheckBox) check_box(*args) Also known as: checkBox, checkbox
Since finding checkboxes by value is very common, you can use this shorthand:
browser.check_box(:name, 'a_name', '1234').set
or
browser.check_box(:name => 'a_name', :value => '1234').set
144 145 146
# File 'lib/celerity/container.rb', line 144 def check_box(*args) CheckBox.new(self, *args) end
- (Celerity::CheckBoxes) checkboxes
152 153 154
# File 'lib/celerity/container.rb', line 152 def checkboxes CheckBoxes.new(self) end
- (Object) container=(container)
Used internally to update the container object.
72 73 74 75 76
# File 'lib/celerity/container.rb', line 72 def container=(container) @container = container @browser = container.browser container end
- (Fixnum) contains_text(expected_text)
Check if the element contains the given text.
45 46 47 48 49 50 51 52 53 54 55 56 57
# File 'lib/celerity/container.rb', line 45 def contains_text(expected_text) assert_exists return nil unless respond_to? :text case expected_text when Regexp text() =~ expected_text when String text().index(expected_text) else raise TypeError, "expected String or Regexp, got #{expected_text.inspect}:#{expected_text.class}" end end
- (Celerity::Dd) dd(*args)
160 161 162
# File 'lib/celerity/container.rb', line 160 def dd(*args) Dd.new(self, *args) end
- (Celerity::Dds) dds
168 169 170
# File 'lib/celerity/container.rb', line 168 def dds Dds.new(self) end
- (Celerity::Div) div(*args)
176 177 178
# File 'lib/celerity/container.rb', line 176 def div(*args) Div.new(self, *args) end
- (Celerity::Divs) divs
184 185 186
# File 'lib/celerity/container.rb', line 184 def divs Divs.new(self) end
- (Celerity::Dl) dl(*args)
192 193 194
# File 'lib/celerity/container.rb', line 192 def dl(*args) Dl.new(self, *args) end
- (Celerity::Dls) dls
200 201 202
# File 'lib/celerity/container.rb', line 200 def dls Dls.new(self) end
- (Celerity::Dt) dt(*args)
208 209 210
# File 'lib/celerity/container.rb', line 208 def dt(*args) Dt.new(self, *args) end
- (Celerity::Dts) dts
216 217 218
# File 'lib/celerity/container.rb', line 216 def dts Dts.new(self) end
- (Celerity::Em) em(*args)
224 225 226
# File 'lib/celerity/container.rb', line 224 def em(*args) Em.new(self, *args) end
- (Celerity::Ems) ems
232 233 234
# File 'lib/celerity/container.rb', line 232 def ems Ems.new(self) end
- (Celerity::FileField) file_field(*args)
240 241 242
# File 'lib/celerity/container.rb', line 240 def file_field(*args) FileField.new(self, *args) end
- (Celerity::FileFields) file_fields
248 249 250
# File 'lib/celerity/container.rb', line 248 def file_fields FileFields.new(self) end
- (Celerity::Form) form(*args)
256 257 258
# File 'lib/celerity/container.rb', line 256 def form(*args) Form.new(self, *args) end
- (Celerity::Forms) forms
264 265 266
# File 'lib/celerity/container.rb', line 264 def forms Forms.new(self) end
- (Celerity::Frame) frame(*args)
272 273 274
# File 'lib/celerity/container.rb', line 272 def frame(*args) Frame.new(self, *args) end
- (Celerity::Frames) frames
280 281 282
# File 'lib/celerity/container.rb', line 280 def frames Frames.new(self) end
- (Celerity::H1) h1(*args)
288 289 290
# File 'lib/celerity/container.rb', line 288 def h1(*args) H1.new(self, *args) end
- (Celerity::H1s) h1s
296 297 298
# File 'lib/celerity/container.rb', line 296 def h1s H1s.new(self) end
- (Celerity::H2) h2(*args)
304 305 306
# File 'lib/celerity/container.rb', line 304 def h2(*args) H2.new(self, *args) end
- (Celerity::H2s) h2s
312 313 314
# File 'lib/celerity/container.rb', line 312 def h2s H2s.new(self) end
- (Celerity::H3) h3(*args)
320 321 322
# File 'lib/celerity/container.rb', line 320 def h3(*args) H3.new(self, *args) end
- (Celerity::H3s) h3s
328 329 330
# File 'lib/celerity/container.rb', line 328 def h3s H3s.new(self) end
- (Celerity::H4) h4(*args)
336 337 338
# File 'lib/celerity/container.rb', line 336 def h4(*args) H4.new(self, *args) end
- (Celerity::H4s) h4s
344 345 346
# File 'lib/celerity/container.rb', line 344 def h4s H4s.new(self) end
- (Celerity::H5) h5(*args)
352 353 354
# File 'lib/celerity/container.rb', line 352 def h5(*args) H5.new(self, *args) end
- (Celerity::H5s) h5s
360 361 362
# File 'lib/celerity/container.rb', line 360 def h5s H5s.new(self) end
- (Celerity::H6) h6(*args)
368 369 370
# File 'lib/celerity/container.rb', line 368 def h6(*args) H6.new(self, *args) end
- (Celerity::H6s) h6s
376 377 378
# File 'lib/celerity/container.rb', line 376 def h6s H6s.new(self) end
384 385 386
# File 'lib/celerity/container.rb', line 384 def hidden(*args) Hidden.new(self, *args) end
392 393 394
# File 'lib/celerity/container.rb', line 392 def hiddens Hiddens.new(self) end
- (Celerity::Image) image(*args)
400 401 402
# File 'lib/celerity/container.rb', line 400 def image(*args) Image.new(self, *args) end
- (Celerity::Images) images
408 409 410
# File 'lib/celerity/container.rb', line 408 def images Images.new(self) end
- (Object) inspect
Override inspect for readability
63 64 65
# File 'lib/celerity/container.rb', line 63 def inspect short_inspect :include => %w[@conditions @object] end
- (Celerity::Label) label(*args)
416 417 418
# File 'lib/celerity/container.rb', line 416 def label(*args) Label.new(self, *args) end
- (Celerity::Labels) labels
424 425 426
# File 'lib/celerity/container.rb', line 424 def labels Labels.new(self) end
- (Celerity::Li) li(*args)
432 433 434
# File 'lib/celerity/container.rb', line 432 def li(*args) Li.new(self, *args) end
- (Celerity::Link) link(*args)
448 449 450
# File 'lib/celerity/container.rb', line 448 def link(*args) Link.new(self, *args) end
- (Celerity::Links) links
456 457 458
# File 'lib/celerity/container.rb', line 456 def links Links.new(self) end
- (Celerity::Lis) lis
440 441 442
# File 'lib/celerity/container.rb', line 440 def lis Lis.new(self) end
- (Celerity::Map) map(*args)
464 465 466
# File 'lib/celerity/container.rb', line 464 def map(*args) Map.new(self, *args) end
- (Celerity::Maps) maps
472 473 474
# File 'lib/celerity/container.rb', line 472 def maps Maps.new(self) end
- (Celerity::Meta) meta(*args)
480 481 482
# File 'lib/celerity/container.rb', line 480 def (*args) Meta.new(self, *args) end
- (Celerity::Metas) metas(*args)
488 489 490
# File 'lib/celerity/container.rb', line 488 def (*args) Metas.new(self, *args) end
- (Celerity::Ol) ol(*args)
496 497 498
# File 'lib/celerity/container.rb', line 496 def ol(*args) Ol.new(self, *args) end
- (Celerity::Ols) ols
504 505 506
# File 'lib/celerity/container.rb', line 504 def ols Ols.new(self) end
- (Celerity::Option) option(*args)
512 513 514
# File 'lib/celerity/container.rb', line 512 def option(*args) Option.new(self, *args) end
- (Celerity::P) p(*args)
520 521 522
# File 'lib/celerity/container.rb', line 520 def p(*args) P.new(self, *args) end
- (Celerity::Pre) pre(*args)
536 537 538
# File 'lib/celerity/container.rb', line 536 def pre(*args) Pre.new(self, *args) end
- (Celerity::Pres) pres
544 545 546
# File 'lib/celerity/container.rb', line 544 def pres Pres.new(self) end
- (Celerity::Ps) ps
528 529 530
# File 'lib/celerity/container.rb', line 528 def ps Ps.new(self) end
- (Celerity::Radio) radio(*args)
Since finding radios by value is very common, you can use this shorthand:
browser.radio(:name, 'a_name', '1234').set
or
browser.radio(:name => 'a_name', :value => '1234').set
560 561 562
# File 'lib/celerity/container.rb', line 560 def radio(*args) Radio.new(self, *args) end
- (Celerity::Radios) radios
568 569 570
# File 'lib/celerity/container.rb', line 568 def radios Radios.new(self) end
- (Celerity::TableRow) row(*args)
576 577 578
# File 'lib/celerity/container.rb', line 576 def row(*args) TableRow.new(self, *args) end
- (Celerity::TableRows) rows
584 585 586
# File 'lib/celerity/container.rb', line 584 def rows TableRows.new(self) end
- (Celerity::SelectList) select_list(*args)
592 593 594
# File 'lib/celerity/container.rb', line 592 def select_list(*args) SelectList.new(self, *args) end
- (Celerity::SelectLists) select_lists
600 601 602
# File 'lib/celerity/container.rb', line 600 def select_lists SelectLists.new(self) end
- (Celerity::Span) span(*args)
608 609 610
# File 'lib/celerity/container.rb', line 608 def span(*args) Span.new(self, *args) end
- (Celerity::Spans) spans
616 617 618
# File 'lib/celerity/container.rb', line 616 def spans Spans.new(self) end
- (Celerity::Spans) strong(*args)
624 625 626
# File 'lib/celerity/container.rb', line 624 def strong(*args) Strong.new(self, *args) end
- (Celerity::Strongs) strongs
632 633 634
# File 'lib/celerity/container.rb', line 632 def strongs Strongs.new(self) end
- (Celerity::Table) table(*args)
640 641 642
# File 'lib/celerity/container.rb', line 640 def table(*args) Table.new(self, *args) end
- (Celerity::Tables) tables
648 649 650
# File 'lib/celerity/container.rb', line 648 def tables Tables.new(self) end
- (Celerity::TableBodies) tbodies Also known as: bodies
664 665 666
# File 'lib/celerity/container.rb', line 664 def tbodies TableBodies.new(self) end
- (Celerity::TableBody) tbody(*args) Also known as: body
656 657 658
# File 'lib/celerity/container.rb', line 656 def tbody(*args) TableBody.new(self, *args) end
- (Celerity::TextField) text_field(*args)
672 673 674
# File 'lib/celerity/container.rb', line 672 def text_field(*args) TextField.new(self, *args) end
- (Celerity::TextFields) text_fields
680 681 682
# File 'lib/celerity/container.rb', line 680 def text_fields TextFields.new(self) end
- (Celerity::TableFooter) tfoot(*args)
688 689 690
# File 'lib/celerity/container.rb', line 688 def tfoot(*args) .new(self, *args) end
- (Celerity::TableFooters) tfoots Also known as: tfeet
696 697 698
# File 'lib/celerity/container.rb', line 696 def tfoots .new(self) end
- (Celerity::Th) th(*args)
Watir’s cells() won’t find
elements. This is a workaround. 708 709 710
# File 'lib/celerity/container.rb', line 708 def th(*args) Th.new(self, *args) end
- (Celerity::TableHeader) thead(*args)
725 726 727
# File 'lib/celerity/container.rb', line 725 def thead(*args) TableHeader.new(self, *args) end
- (Celerity::TableHeaders) theads
733 734 735
# File 'lib/celerity/container.rb', line 733 def theads TableHeaders.new(self) end
- (Object) ths
FIXME: implement or change api,
717 718 719
# File 'lib/celerity/container.rb', line 717 def ths raise NotImplementedError end
- (Celerity::Ul) ul(*args)
741 742 743
# File 'lib/celerity/container.rb', line 741 def ul(*args) Ul.new(self, *args) end
- (Celerity::Uls) uls
749 750 751
# File 'lib/celerity/container.rb', line 749 def uls Uls.new(self) end