Module: Celerity::Container

Includes:
Exception, ShortInspect
Included in:
Browser, Element, Form, Frame, Table, TableCell
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 ...>

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ShortInspect

#short_inspect

Instance Attribute Details

#browserObject (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

Instance Method Details

#area(*args) ⇒ Celerity::Area

Returns:



86
87
88
# File 'lib/celerity/container.rb', line 86

def area(*args)
  Area.new(self, *args)
end

#areasCelerity::Areas

Returns:



94
95
96
# File 'lib/celerity/container.rb', line 94

def areas
  Areas.new(self)
end

#button(*args) ⇒ Celerity::Button

Returns:



102
103
104
# File 'lib/celerity/container.rb', line 102

def button(*args)
  Button.new(self, *args)
end

#buttonsCelerity::Buttons

Returns:



110
111
112
# File 'lib/celerity/container.rb', line 110

def buttons
  Buttons.new(self)
end

#cell(*args) ⇒ Celerity::TableCell

Returns:



118
119
120
# File 'lib/celerity/container.rb', line 118

def cell(*args)
  TableCell.new(self, *args)
end

#cellsCelerity::TableCells



126
127
128
# File 'lib/celerity/container.rb', line 126

def cells
  TableCells.new(self)
end

#check_box(*args) ⇒ Celerity::CheckBox 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

Returns:



142
143
144
# File 'lib/celerity/container.rb', line 142

def check_box(*args)
  CheckBox.new(self, *args)
end

#checkboxesCelerity::CheckBoxes



150
151
152
# File 'lib/celerity/container.rb', line 150

def checkboxes
  CheckBoxes.new(self)
end

#container=(container) ⇒ 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.

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

#contains_text(expected_text) ⇒ Fixnum?

Check if the element contains the given text.

Parameters:

  • expected_text (String, Regexp)

    The text to look for.

Returns:

  • (Fixnum, nil)

    The index of the matched text, or nil if it doesn’t match.



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

#dd(*args) ⇒ Celerity::Dd

Returns:



158
159
160
# File 'lib/celerity/container.rb', line 158

def dd(*args)
  Dd.new(self, *args)
end

#ddsCelerity::Dds

Returns:



166
167
168
# File 'lib/celerity/container.rb', line 166

def dds
  Dds.new(self)
end

#div(*args) ⇒ Celerity::Div

Returns:



174
175
176
# File 'lib/celerity/container.rb', line 174

def div(*args)
  Div.new(self, *args)
end

#divsCelerity::Divs

Returns:



182
183
184
# File 'lib/celerity/container.rb', line 182

def divs
  Divs.new(self)
end

#dl(*args) ⇒ Celerity::Dl

Returns:



190
191
192
# File 'lib/celerity/container.rb', line 190

def dl(*args)
  Dl.new(self, *args)
end

#dlsCelerity::Dls

Returns:



198
199
200
# File 'lib/celerity/container.rb', line 198

def dls
  Dls.new(self)
end

#dt(*args) ⇒ Celerity::Dt

Returns:



206
207
208
# File 'lib/celerity/container.rb', line 206

def dt(*args)
  Dt.new(self, *args)
end

#dtsCelerity::Dts

Returns:



214
215
216
# File 'lib/celerity/container.rb', line 214

def dts
  Dts.new(self)
end

#em(*args) ⇒ Celerity::Em

Returns:



222
223
224
# File 'lib/celerity/container.rb', line 222

def em(*args)
  Em.new(self, *args)
end

#emsCelerity::Ems

Returns:



230
231
232
# File 'lib/celerity/container.rb', line 230

def ems
  Ems.new(self)
end

#file_field(*args) ⇒ Celerity::FileField

Returns:



238
239
240
# File 'lib/celerity/container.rb', line 238

def file_field(*args)
  FileField.new(self, *args)
end

#file_fieldsCelerity::FileFields



246
247
248
# File 'lib/celerity/container.rb', line 246

def file_fields
  FileFields.new(self)
end

#form(*args) ⇒ Celerity::Form

Returns:



254
255
256
# File 'lib/celerity/container.rb', line 254

def form(*args)
  Form.new(self, *args)
end

#formsCelerity::Forms

Returns:



262
263
264
# File 'lib/celerity/container.rb', line 262

def forms
  Forms.new(self)
end

#frame(*args) ⇒ Celerity::Frame

Returns:



270
271
272
# File 'lib/celerity/container.rb', line 270

def frame(*args)
  Frame.new(self, *args)
end

#framesCelerity::Frames

Returns:



278
279
280
# File 'lib/celerity/container.rb', line 278

def frames
  Frames.new(self)
end

#h1(*args) ⇒ Celerity::H1

Returns:



286
287
288
# File 'lib/celerity/container.rb', line 286

def h1(*args)
  H1.new(self, *args)
end

#h1sCelerity::H1s

Returns:



294
295
296
# File 'lib/celerity/container.rb', line 294

def h1s
  H1s.new(self)
end

#h2(*args) ⇒ Celerity::H2

Returns:



302
303
304
# File 'lib/celerity/container.rb', line 302

def h2(*args)
  H2.new(self, *args)
end

#h2sCelerity::H2s

Returns:



310
311
312
# File 'lib/celerity/container.rb', line 310

def h2s
  H2s.new(self)
end

#h3(*args) ⇒ Celerity::H3

Returns:



318
319
320
# File 'lib/celerity/container.rb', line 318

def h3(*args)
  H3.new(self, *args)
end

#h3sCelerity::H3s

Returns:



326
327
328
# File 'lib/celerity/container.rb', line 326

def h3s
  H3s.new(self)
end

#h4(*args) ⇒ Celerity::H4

Returns:



334
335
336
# File 'lib/celerity/container.rb', line 334

def h4(*args)
  H4.new(self, *args)
end

#h4sCelerity::H4s

Returns:



342
343
344
# File 'lib/celerity/container.rb', line 342

def h4s
  H4s.new(self)
end

#h5(*args) ⇒ Celerity::H5

Returns:



350
351
352
# File 'lib/celerity/container.rb', line 350

def h5(*args)
  H5.new(self, *args)
end

#h5sCelerity::H5s

Returns:



358
359
360
# File 'lib/celerity/container.rb', line 358

def h5s
  H5s.new(self)
end

#h6(*args) ⇒ Celerity::H6

Returns:



366
367
368
# File 'lib/celerity/container.rb', line 366

def h6(*args)
  H6.new(self, *args)
end

#h6sCelerity::H6s

Returns:



374
375
376
# File 'lib/celerity/container.rb', line 374

def h6s
  H6s.new(self)
end

#hidden(*args) ⇒ Celerity::Hidden

Returns:



382
383
384
# File 'lib/celerity/container.rb', line 382

def hidden(*args)
  Hidden.new(self, *args)
end

#hiddensCelerity::Hiddens

Returns:



390
391
392
# File 'lib/celerity/container.rb', line 390

def hiddens
  Hiddens.new(self)
end

#image(*args) ⇒ Celerity::Image

Returns:



398
399
400
# File 'lib/celerity/container.rb', line 398

def image(*args)
  Image.new(self, *args)
end

#imagesCelerity::Images

Returns:



406
407
408
# File 'lib/celerity/container.rb', line 406

def images
  Images.new(self)
end

#inspectObject

Override inspect for readability



63
64
65
# File 'lib/celerity/container.rb', line 63

def inspect
  short_inspect :include => %w[@conditions @object]
end

#label(*args) ⇒ Celerity::Label

Returns:



414
415
416
# File 'lib/celerity/container.rb', line 414

def label(*args)
  Label.new(self, *args)
end

#labelsCelerity::Labels

Returns:



422
423
424
# File 'lib/celerity/container.rb', line 422

def labels
  Labels.new(self)
end

#li(*args) ⇒ Celerity::Li

Returns:



430
431
432
# File 'lib/celerity/container.rb', line 430

def li(*args)
  Li.new(self, *args)
end

Returns:



446
447
448
# File 'lib/celerity/container.rb', line 446

def link(*args)
  Link.new(self, *args)
end

Returns:



454
455
456
# File 'lib/celerity/container.rb', line 454

def links
  Links.new(self)
end

#lisCelerity::Lis

Returns:



438
439
440
# File 'lib/celerity/container.rb', line 438

def lis
  Lis.new(self)
end

#map(*args) ⇒ Celerity::Map

Returns:



462
463
464
# File 'lib/celerity/container.rb', line 462

def map(*args)
  Map.new(self, *args)
end

#mapsCelerity::Maps

Returns:



470
471
472
# File 'lib/celerity/container.rb', line 470

def maps
  Maps.new(self)
end

#meta(*args) ⇒ Celerity::Meta

Returns:



478
479
480
# File 'lib/celerity/container.rb', line 478

def meta(*args)
  Meta.new(self, *args)
end

#metas(*args) ⇒ Celerity::Metas

Returns:



486
487
488
# File 'lib/celerity/container.rb', line 486

def metas(*args)
  Metas.new(self, *args)
end

#ol(*args) ⇒ Celerity::Ol

Returns:



494
495
496
# File 'lib/celerity/container.rb', line 494

def ol(*args)
  Ol.new(self, *args)
end

#olsCelerity::Ols

Returns:



502
503
504
# File 'lib/celerity/container.rb', line 502

def ols
  Ols.new(self)
end

#option(*args) ⇒ Celerity::Option

Returns:



510
511
512
# File 'lib/celerity/container.rb', line 510

def option(*args)
  Option.new(self, *args)
end

#p(*args) ⇒ Celerity::P

Returns:



518
519
520
# File 'lib/celerity/container.rb', line 518

def p(*args)
  P.new(self, *args)
end

#pre(*args) ⇒ Celerity::Pre

Returns:



534
535
536
# File 'lib/celerity/container.rb', line 534

def pre(*args)
  Pre.new(self, *args)
end

#presCelerity::Pres

Returns:



542
543
544
# File 'lib/celerity/container.rb', line 542

def pres
  Pres.new(self)
end

#psCelerity::Ps

Returns:



526
527
528
# File 'lib/celerity/container.rb', line 526

def ps
  Ps.new(self)
end

#radio(*args) ⇒ Celerity::Radio

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

Returns:



558
559
560
# File 'lib/celerity/container.rb', line 558

def radio(*args)
  Radio.new(self, *args)
end

#radiosCelerity::Radios

Returns:



566
567
568
# File 'lib/celerity/container.rb', line 566

def radios
  Radios.new(self)
end

#row(*args) ⇒ Celerity::TableRow

Returns:



574
575
576
# File 'lib/celerity/container.rb', line 574

def row(*args)
  TableRow.new(self, *args)
end

#rowsCelerity::TableRows

Returns:



582
583
584
# File 'lib/celerity/container.rb', line 582

def rows
  TableRows.new(self)
end

#select_list(*args) ⇒ Celerity::SelectList



590
591
592
# File 'lib/celerity/container.rb', line 590

def select_list(*args)
  SelectList.new(self, *args)
end

#select_listsCelerity::SelectLists



598
599
600
# File 'lib/celerity/container.rb', line 598

def select_lists
  SelectLists.new(self)
end

#span(*args) ⇒ Celerity::Span

Returns:



606
607
608
# File 'lib/celerity/container.rb', line 606

def span(*args)
  Span.new(self, *args)
end

#spansCelerity::Spans

Returns:



614
615
616
# File 'lib/celerity/container.rb', line 614

def spans
  Spans.new(self)
end

#strong(*args) ⇒ Celerity::Spans

Returns:



622
623
624
# File 'lib/celerity/container.rb', line 622

def strong(*args)
  Strong.new(self, *args)
end

#strongsCelerity::Strongs

Returns:



630
631
632
# File 'lib/celerity/container.rb', line 630

def strongs
  Strongs.new(self)
end

#table(*args) ⇒ Celerity::Table

Returns:



638
639
640
# File 'lib/celerity/container.rb', line 638

def table(*args)
  Table.new(self, *args)
end

#tablesCelerity::Tables

Returns:



646
647
648
# File 'lib/celerity/container.rb', line 646

def tables
  Tables.new(self)
end

#tbodiesCelerity::TableBodies Also known as: bodies



662
663
664
# File 'lib/celerity/container.rb', line 662

def tbodies
  TableBodies.new(self)
end

#tbody(*args) ⇒ Celerity::TableBody Also known as: body

Returns:



654
655
656
# File 'lib/celerity/container.rb', line 654

def tbody(*args)
  TableBody.new(self, *args)
end

#text_field(*args) ⇒ Celerity::TextField

Returns:



670
671
672
# File 'lib/celerity/container.rb', line 670

def text_field(*args)
  TextField.new(self, *args)
end

#text_fieldsCelerity::TextFields



678
679
680
# File 'lib/celerity/container.rb', line 678

def text_fields
  TextFields.new(self)
end

#tfoot(*args) ⇒ Celerity::TableFooter



686
687
688
# File 'lib/celerity/container.rb', line 686

def tfoot(*args)
  TableFooter.new(self, *args)
end

#tfootsCelerity::TableFooters Also known as: tfeet



694
695
696
# File 'lib/celerity/container.rb', line 694

def tfoots
  TableFooters.new(self)
end

#th(*args) ⇒ Celerity::Th

Watir’s cells() won’t find <th> elements. This is a workaround.

Returns:



706
707
708
# File 'lib/celerity/container.rb', line 706

def th(*args)
  Th.new(self, *args)
end

#thead(*args) ⇒ Celerity::TableHeader



723
724
725
# File 'lib/celerity/container.rb', line 723

def thead(*args)
  TableHeader.new(self, *args)
end

#theadsCelerity::TableHeaders



731
732
733
# File 'lib/celerity/container.rb', line 731

def theads
  TableHeaders.new(self)
end

#thsObject

FIXME: implement or change api,

Raises:

  • (NotImplementedError)

See Also:



715
716
717
# File 'lib/celerity/container.rb', line 715

def ths
  raise NotImplementedError
end

#ul(*args) ⇒ Celerity::Ul

Returns:



739
740
741
# File 'lib/celerity/container.rb', line 739

def ul(*args)
  Ul.new(self, *args)
end

#ulsCelerity::Uls

Returns:



747
748
749
# File 'lib/celerity/container.rb', line 747

def uls
  Uls.new(self)
end