Module: Watir::Container
- Includes:
- Exception
- Included in:
- Element, ElementMapper, Form, IE, ModalDialog, Table, TableCell
- Defined in:
- lib/watir/container.rb,
lib/watir/camel_case.rb
Overview
This module contains the factory methods that are used to access most html objects
For example, to access a button on a web page that has the following html
<input type=button name='b1' value='Click Me' onClick='javascript:doSomething()'>
the following watir code could be used to click the button
browser.(:name, 'b1').click
or to find the name attribute
browser.(:value, 'Click Me').name
there are many methods available to the Button object – Is includable for classes that have @container, document and ole_inner_elements
Instance Attribute Summary collapse
-
#activeObjectHighLightColor ⇒ Object
The color we want to use for the active object.
-
#page_container ⇒ Object
The PageContainer object containing this element.
-
#type_keys ⇒ Object
Returns the value of attribute type_keys.
-
#typingspeed ⇒ Object
This is used to change the typing speed when entering text on a page.
Instance Method Summary collapse
-
#area(how, what = nil) ⇒ Object
This is the main method for accessing area tags - msdn.microsoft.com/workshop/author/dhtml/reference/objects/area.asp?frame=true * how - symbol - how we access the area * what - string, integer or regular expression - what we are looking for,.
-
#areas ⇒ Object
this is the main method for accessing the areas iterator.
-
#button(how, what = nil) ⇒ Object
This is the main method for accessing a button.
-
#buttons ⇒ Object
this is the main method for accessing the buttons iterator.
-
#cell(how, what = nil) ⇒ Object
this method accesses a table cell.
- #cells ⇒ Object
-
#checkbox(how, what = nil, value = nil) ⇒ Object
(also: #checkBox)
This is the main method for accessing a check box.
-
#checkboxes ⇒ Object
this is the method for accessing the check boxes iterator.
-
#dds ⇒ Object
this is the main method for accessing the dds iterator.
-
#divs ⇒ Object
this is the main method for accessing the divs iterator.
-
#dls ⇒ Object
this is the main method for accessing the dls iterator.
-
#dts ⇒ Object
this is the main method for accessing the dts iterator.
-
#element(how, what) ⇒ Object
This is the main method for accessing a generic element with a given attibute * how - symbol - how we access the element.
-
#element_by_css(selector) ⇒ Object
abstract method for locating an element using a CSS selector expression.
-
#elements(how, what) ⇒ Object
this is the main method for accessing generic html elements by an attribute.
-
#ems ⇒ Object
this is the main method for accessing the ems iterator.
-
#file_field(how, what = nil) ⇒ Object
(also: #fileField)
This is the main method for accessing a file field.
-
#file_fields ⇒ Object
this is the main method for accessing the file_fields iterator.
-
#form(how, what = nil) ⇒ Object
this method is used to access a form.
-
#forms ⇒ Object
this is the main method for accessing the forms iterator.
-
#frame(how, what = nil) ⇒ Object
this method is the main way of accessing a frame * how - how the frame is accessed.
-
#frames ⇒ Object
this is the main method for accessing the frames iterator.
-
#hidden(how, what = nil) ⇒ Object
This is the main method for accessing a hidden field.
-
#hiddens ⇒ Object
this is the method for accessing the hiddens iterator.
-
#image(how, what = nil) ⇒ Object
This is the main method for accessing images - normally an
<img src="image.gif">
HTML tag. -
#images ⇒ Object
This is the main method for accessing the images collection.
-
#labels ⇒ Object
this is the main method for accessing the labels iterator.
-
#link(how, what = nil) ⇒ Object
This is the main method for accessing a link.
-
#links ⇒ Object
This is the main method for accessing the links collection.
-
#lis ⇒ Object
this is the main method for accessing the lis iterator.
-
#locate_all_elements(how, what) ⇒ Object
returns the the locator object so you can iterate over the elements using #each.
-
#locate_input_element(how, what, types, value = nil, klass = nil) ⇒ Object
Returns the specified ole object for input elements on a web page.
-
#locate_tagged_element(tag, how, what) ⇒ Object
returns the ole object for the specified element.
-
#log(what) ⇒ Object
Write the specified string to the log.
-
#map(how, what = nil) ⇒ Object
This is the main method for accessing map tags - msdn.microsoft.com/workshop/author/dhtml/reference/objects/map.asp?frame=true * how - symbol - how we access the map, * what - string, integer or regular expression - what we are looking for,.
-
#maps ⇒ Object
this is the main method for accessing the maps iterator.
-
#modal_dialog(how = nil, what = nil) ⇒ Object
Access a modal web dialog, which is a PageContainer, like IE or Frame.
-
#popup ⇒ Object
This is the main method for accessing JavaScript popups.
-
#pres ⇒ Object
this is the main method for accessing the ps iterator.
-
#ps ⇒ Object
this is the main method for accessing the ps iterator.
-
#radio(how, what = nil, value = nil) ⇒ Object
This is the main method for accessing a radio button.
-
#radios ⇒ Object
This is the method for accessing the radio buttons iterator.
-
#row(how, what = nil) ⇒ Object
this method accesses a table row.
- #rows ⇒ Object
-
#select_list(how, what = nil) ⇒ Object
(also: #selectBox)
This is the main method for accessing a selection list.
-
#select_lists ⇒ Object
this is the method for accessing the select lists iterator.
-
#set_container(container) ⇒ Object
:nodoc:.
-
#show_all_objects ⇒ Object
This method shows the available objects on the current page.
-
#spans ⇒ Object
this is the main method for accessing the spans iterator.
-
#strongs ⇒ Object
this is the main method for accessing the Strongs iterator.
-
#table(how, what = nil) ⇒ Object
This method is used to get a table from the page.
-
#tables ⇒ Object
this is the main method for accessing the tables iterator.
-
#text_field(how, what = nil) ⇒ Object
(also: #textField)
This is the main method for accessing a text field.
-
#text_fields ⇒ Object
this is the method for accessing the text_fields iterator.
-
#wait(no_sleep = false) ⇒ Object
(also: #waitForIE)
Wait until Browser has finished loading the page.
Instance Attribute Details
#activeObjectHighLightColor ⇒ Object
The color we want to use for the active object. This can be any valid web-friendly color.
30 31 32 |
# File 'lib/watir/container.rb', line 30 def activeObjectHighLightColor @activeObjectHighLightColor end |
#page_container ⇒ Object
The PageContainer object containing this element
32 33 34 |
# File 'lib/watir/container.rb', line 32 def page_container @page_container end |
#type_keys ⇒ Object
Returns the value of attribute type_keys.
28 29 30 |
# File 'lib/watir/container.rb', line 28 def type_keys @type_keys end |
#typingspeed ⇒ Object
This is used to change the typing speed when entering text on a page.
27 28 29 |
# File 'lib/watir/container.rb', line 27 def typingspeed @typingspeed end |
Instance Method Details
#area(how, what = nil) ⇒ Object
This is the main method for accessing area tags - msdn.microsoft.com/workshop/author/dhtml/reference/objects/area.asp?frame=true
* how - symbol - how we access the area
* what - string, integer or regular expression - what we are looking for,
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a area object
Typical Usage
browser.area(:id, /list/) # access the first area that matches list.
browser.area(:index,2) # access the second area on the page
browser.area(:title, "A Picture") # access a area using the tooltip text. See http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/title_1.asp?frame=true
573 574 575 |
# File 'lib/watir/container.rb', line 573 def area(how, what=nil) return Area.new(self, how, what) end |
#areas ⇒ Object
this is the main method for accessing the areas iterator.
Returns a areas object
Typical usage:
browser.areas.each { |s| puts s.to_s } # iterate through all the areas on the page
browser.areas[1].to_s # goto the first area on the page
browser.areas.length # show how many areas are on the page.
587 588 589 |
# File 'lib/watir/container.rb', line 587 def areas return Areas.new(self) end |
#button(how, what = nil) ⇒ Object
This is the main method for accessing a button. Often declared as an <input type = submit>
tag.
* how - symbol - how we access the button, :index, :id, :name etc
* what - string, integer or regular expression - what we are looking for,
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
Returns a Button object.
Typical usage
browser.(:id, 'b_1') # access the button with an ID of b_1
browser.(:name, 'verify_data') # access the button with a name of verify_data
browser.(:value, 'Login') # access the button with a value (the text displayed on the button) of Login
browser.(:caption, 'Login') # same as above
browser.(:value, /Log/) # access the button that has text matching /Log/
browser.(:index, 2) # access the second button on the page (1 based, so the first button is accessed with :index,1)
browser.(:class, 'my_custom_button_class') # access the button with a class of my_custom_button_class
browser.(:xpath, "//input[@value='Click Me']/") # access the button with a value of Click Me
Accessing a Button nested within another element
browser.div(:class, 'xyz').(:index, 2) # access a div of class xyz, and the 2nd button within that div
If only a single parameter is supplied, then :value is used
browser.('Click Me') # access the button with a value of Click Me
239 240 241 242 |
# File 'lib/watir/container.rb', line 239 def (how, what=nil) how, what = process_default :value, how, what Button.new(self, how, what) end |
#buttons ⇒ Object
this is the main method for accessing the buttons iterator. It returns a Buttons object
Typical usage:
browser..each { |b| puts b.to_s } # iterate through all the buttons on the page
browser.[1].to_s # goto the first button on the page
browser..length # show how many buttons are on the page.
251 252 253 |
# File 'lib/watir/container.rb', line 251 def Buttons.new(self) end |
#cell(how, what = nil) ⇒ Object
this method accesses a table cell. how - symbol - how we access the cell, valid values are
:id - find the table cell with given id.
:xpath - find the table cell using xpath query.
returns a TableCell Object
178 179 180 |
# File 'lib/watir/container.rb', line 178 def cell(how, what=nil) TableCell.new(self, how, what) end |
#cells ⇒ Object
181 182 183 |
# File 'lib/watir/container.rb', line 181 def cells TableCells.new(self) end |
#checkbox(how, what = nil, value = nil) ⇒ Object Also known as: checkBox
This is the main method for accessing a check box. Usually an <input type = checkbox>
HTML tag.
* how - symbol - how we access the check box - :index, :id, :name etc
* what - string, integer or regular expression - what we are looking for,
* value - string - when there are multiple objects with different value attributes, this can be used to find the correct object
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a CheckBox object
Typical usage
browser.checkbox(:id, 'send_email') # access the check box with an id of send_mail
browser.checkbox(:name, 'send_copy') # access the check box with a name of send_copy
browser.checkbox(:name, /n_/) # access the first check box whose name matches n_
browser.checkbox(:index, 2) # access the second check box on the page (1 based, so the first field is accessed with :index,1)
In many instances, checkboxes on an html page have the same name, but are identified by different values. An example is shown next.
<input type = checkbox name = email_frequency value = 'daily' > Daily Email
<input type = checkbox name = email_frequency value = 'Weekly'> Weekly Email
<input type = checkbox name = email_frequency value = 'monthly'>Monthly Email
Watir can access these using the following:
browser.checkbox(:id, 'day_to_send', 'monday') # access the check box with an id of day_to_send and a value of monday
browser.checkbox(:name,'email_frequency', 'weekly') # access the check box with a name of email_frequency and a value of 'weekly'
browser.checkbox(:xpath, "//input[@name='email_frequency' and @value='daily']/") # access the checkbox with a name of email_frequency and a value of 'daily'
404 405 406 |
# File 'lib/watir/container.rb', line 404 def checkbox(how, what=nil, value=nil) # should be "check_box" ? CheckBox.new(self, how, what, value) end |
#checkboxes ⇒ Object
this is the method for accessing the check boxes iterator. Returns a CheckBoxes object
Typical usage:
browser.checkboxes.each { |c| puts c.to_s } # iterate through all the check boxes on the page
browser.checkboxes[1].to_s # goto the first check box on the page
browser.checkboxes.length # show how many check boxes are on the page.
415 416 417 |
# File 'lib/watir/container.rb', line 415 def checkboxes CheckBoxes.new(self) end |
#dds ⇒ Object
this is the main method for accessing the dds iterator. Returns a Dds collection
Typical usage:
browser.dds.each { |d| puts d.to_s } # iterate through all the dds on the page
browser.dds[1].to_s # goto the first dd on the page
browser.dds.length # show how many dds are on the page.
662 663 664 |
# File 'lib/watir/container.rb', line 662 def dds Dds.new(self) end |
#divs ⇒ Object
this is the main method for accessing the divs iterator. Returns a Divs collection
Typical usage:
browser.divs.each { |d| puts d.to_s } # iterate through all the divs on the page
browser.divs[1].to_s # goto the first div on the page
browser.divs.length # show how many divs are on the page.
638 639 640 |
# File 'lib/watir/container.rb', line 638 def divs Divs.new(self) end |
#dls ⇒ Object
this is the main method for accessing the dls iterator. Returns a Dls collection
Typical usage:
browser.dls.each { |d| puts d.to_s } # iterate through all the dls on the page
browser.dls[1].to_s # goto the first dl on the page
browser.dls.length # show how many dls are on the page.
650 651 652 |
# File 'lib/watir/container.rb', line 650 def dls Dls.new(self) end |
#dts ⇒ Object
this is the main method for accessing the dts iterator. Returns a Dts collection
Typical usage:
browser.dts.each { |d| puts d.to_s } # iterate through all the dts on the page
browser.dts[1].to_s # goto the first dt on the page
browser.dts.length # show how many dts are on the page.
674 675 676 |
# File 'lib/watir/container.rb', line 674 def dts Dts.new(self) end |
#element(how, what) ⇒ Object
This is the main method for accessing a generic element with a given attibute
* how - symbol - how we access the element. Supports all values except :index and :xpath
* what - string, integer or regular expression - what we are looking for,
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns an Watir::Element object
Typical Usage
ie.element(:class, /foo/) # access the first element with class 'foo'. We can use a string in place of the regular expression
ie.element(:id, "11") # access the first element that matches an id
774 775 776 |
# File 'lib/watir/container.rb', line 774 def element(how, what) return HTMLElement.new(self, how, what) end |
#element_by_css(selector) ⇒ Object
abstract method for locating an element using a CSS selector expression
869 870 871 |
# File 'lib/watir/container.rb', line 869 def element_by_css(selector) raise MissingWayOfFindingObjectException, "CSS selectors not yet supported for #{self.class.name}" end |
#elements(how, what) ⇒ Object
this is the main method for accessing generic html elements by an attribute
Returns a HTMLElements object
Typical usage:
ie.elements(:class, 'test').each { |l| puts l.to_s } # iterate through all elements of a given attribute
ie.elements(:alt, 'foo')[1].to_s # get the first element of a given attribute
ie.elements(:id, 'foo').length # show how many elements are foung in the collection
788 789 790 |
# File 'lib/watir/container.rb', line 788 def elements(how, what) return HTMLElements.new(self, how, what) end |
#ems ⇒ Object
this is the main method for accessing the ems iterator. Returns a Ems collection
Typical usage:
browser.ems.each { |d| puts d.to_s } # iterate through all the ems on the page
browser.ems[1].to_s # goto the first em on the page
browser.ems.length # show how many ems are on the page.
686 687 688 |
# File 'lib/watir/container.rb', line 686 def ems Ems.new(self) end |
#file_field(how, what = nil) ⇒ Object Also known as: fileField
This is the main method for accessing a file field. Usually an <input type = file>
HTML tag.
* how - symbol - how we access the field, valid values are
:index - find the file field using index
:id - find the file field using id attribute
:name - find the file field using name attribute
:xpath - find the file field using xpath query
* what - string, integer, regular expression, or xpath query - what we are looking for,
returns a FileField object
Typical Usage
browser.file_field(:id, 'up_1') # access the file upload field with an ID of up_1
browser.file_field(:name, 'upload') # access the file upload field with a name of upload
browser.file_field(:index, 2) # access the second file upload on the page (1 based, so the first field is accessed with :index,1)
271 272 273 |
# File 'lib/watir/container.rb', line 271 def file_field(how, what=nil) FileField.new(self, how, what) end |
#file_fields ⇒ Object
this is the main method for accessing the file_fields iterator. It returns a FileFields object
Typical usage:
browser.file_fields.each { |f| puts f.to_s } # iterate through all the file fields on the page
browser.file_fields[1].to_s # goto the first file field on the page
browser.file_fields.length # show how many file fields are on the page.
282 283 284 |
# File 'lib/watir/container.rb', line 282 def file_fields FileFields.new(self) end |
#form(how, what = nil) ⇒ Object
this method is used to access a form. available ways of accessing it are, :index, :name, :id, :method, :action, :xpath
* how - symbol - What mecahnism we use to find the form, one of
the above. NOTE if what is not supplied this parameter is the NAME of the form
* what - String - the text associated with the symbol
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a Form object
128 129 130 131 |
# File 'lib/watir/container.rb', line 128 def form(how, what=nil) how, what = process_default :name, how, what Form.new(self, how, what) end |
#forms ⇒ Object
this is the main method for accessing the forms iterator. Returns a Forms collection
Typical usage:
browser.forms.each { |f| puts f.src } # iterate through all the forms on the page
browser.forms[1].to_s # goto the first form on the page
browser.forms.length # show how many forms are on the page.
141 142 143 |
# File 'lib/watir/container.rb', line 141 def forms Forms.new(self) end |
#frame(how, what = nil) ⇒ Object
this method is the main way of accessing a frame
* how - how the frame is accessed. This can also just be the name of the frame.
* what - what we want to access.
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a Frame object
Typical usage:
browser.frame(:index, 1)
browser.frame(:name, 'main_frame')
browser.frame('main_frame') # in this case, just a name is supplied
102 103 104 105 |
# File 'lib/watir/container.rb', line 102 def frame(how, what=nil) how, what = process_default :name, how, what Frame.new(self, how, what) end |
#frames ⇒ Object
this is the main method for accessing the frames iterator. Returns a Frames collection
Typical usage:
browser.frames.each { |f| puts f.src } # iterate through all the frames on the page
browser.frames[1].to_s # goto the first frame on the page
browser.frames.length # show how many frames are on the page.
115 116 117 |
# File 'lib/watir/container.rb', line 115 def frames Frames.new(self) end |
#hidden(how, what = nil) ⇒ Object
This is the main method for accessing a hidden field. Usually an <input type = hidden>
HTML tag
* how - symbol - how we access the hidden field, :index, :id, :name etc
* what - string, integer or regular expression - what we are looking for,
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a Hidden object
Typical usage
browser.hidden(:id, 'session_id') # access the hidden field with an ID of session_id
browser.hidden(:name, 'temp_value') # access the hidden field with a name of temp_value
browser.hidden(:index, 2) # access the second hidden field on the page (1 based, so the first field is accessed with :index,1)
browser.hidden(:xpath, "//input[@type='hidden' and @id='session_value']/") # access the hidden field with an ID of session_id
331 332 333 |
# File 'lib/watir/container.rb', line 331 def hidden(how, what=nil) Hidden.new(self, how, what) end |
#hiddens ⇒ Object
this is the method for accessing the hiddens iterator. It returns a Hiddens object
Typical usage:
browser.hiddens.each { |t| puts t.to_s } # iterate through all the hidden fields on the page
browser.hiddens[1].to_s # goto the first hidden field on the page
browser.hiddens.length # show how many hidden fields are on the page.
342 343 344 |
# File 'lib/watir/container.rb', line 342 def hiddens Hiddens.new(self) end |
#image(how, what = nil) ⇒ Object
This is the main method for accessing images - normally an <img src="image.gif">
HTML tag.
* how - symbol - how we access the image, :index, :id, :name, :src, :title or :alt are supported
* what - string, integer or regular expression - what we are looking for,
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns an Image object
Typical Usage
browser.image(:src, /myPic/) # access the first image that matches myPic. We can use a string in place of the regular expression
# but the complete path must be used, browser.image(:src, 'http://myserver.com/my_path/my_image.jpg')
browser.image(:index,2) # access the second image on the page
browser.image(:alt, "A Picture") # access an image using the alt text
browser.image(:xpath, "//img[@alt='A Picture']/") # access an image using the alt text
607 608 609 |
# File 'lib/watir/container.rb', line 607 def image(how, what=nil) Image.new(self, how, what) end |
#images ⇒ Object
This is the main method for accessing the images collection. Returns an Images object
Typical usage:
browser.images.each { |i| puts i.to_s } # iterate through all the images on the page
browser.images[1].to_s # goto the first image on the page
browser.images.length # show how many images are on the page.
619 620 621 |
# File 'lib/watir/container.rb', line 619 def images Images.new(self) end |
#labels ⇒ Object
this is the main method for accessing the labels iterator. It returns a Labels object
Returns a Labels object
Typical usage:
browser.labels.each { |l| puts l.to_s } # iterate through all the labels on the page
browser.labels[1].to_s # goto the first label on the page
browser.labels.length # show how many labels are on the page.
757 758 759 |
# File 'lib/watir/container.rb', line 757 def labels Labels.new(self) end |
#link(how, what = nil) ⇒ Object
This is the main method for accessing a link.
* how - symbol - how we access the link, :index, :id, :name, :title, :text, :url
* what - string, integer or regular expression - what we are looking for,
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a Link object
Typical Usage
browser.link(:url, /login/) # access the first link whose url matches login. We can use a string in place of the regular expression
# but the complete path must be used, browser.link(:url, 'http://myserver.com/my_path/login.asp')
browser.link(:index,2) # access the second link on the page
browser.link(:title, "Picture") # access a link using the tool tip
browser.link(:text, 'Click Me') # access the link that has Click Me as its text
browser.link(:xpath, "//a[contains(.,'Click Me')]/") # access the link with Click Me as its text
478 479 480 |
# File 'lib/watir/container.rb', line 478 def link(how, what=nil) Link.new(self, how, what) end |
#links ⇒ Object
This is the main method for accessing the links collection. Returns a Links object
Typical usage:
browser.links.each { |l| puts l.to_s } # iterate through all the links on the page
browser.links[1].to_s # goto the first link on the page
browser.links.length # show how many links are on the page.
490 491 492 |
# File 'lib/watir/container.rb', line 490 def links Links.new(self) end |
#lis ⇒ Object
this is the main method for accessing the lis iterator.
Returns a lis object
Typical usage:
browser.lis.each { |s| puts s.to_s } # iterate through all the lis on the page
browser.lis[1].to_s # goto the first li on the page
browser.lis.length # show how many lis are on the page.
522 523 524 |
# File 'lib/watir/container.rb', line 522 def lis return Lis.new(self) end |
#locate_all_elements(how, what) ⇒ Object
returns the the locator object so you can iterate over the elements using #each
882 883 884 885 886 |
# File 'lib/watir/container.rb', line 882 def locate_all_elements(how, what) locator = ElementLocator.new(self) locator.set_specifier(how, what) locator end |
#locate_input_element(how, what, types, value = nil, klass = nil) ⇒ Object
Returns the specified ole object for input elements on a web page.
This method is used internally by Watir and should not be used externally. It cannot be marked as private because of the way mixins and inheritance work in watir
* how - symbol - the way we look for the object. Supported values are
- :name
- :id
- :index
- :value etc
* what - string that we are looking for, ex. the name, or id tag attribute or index of the object we are looking for.
* types - what object types we will look at.
* value - used for objects that have one name, but many values. ex. radio lists and checkboxes
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 |
# File 'lib/watir/container.rb', line 847 def locate_input_element(how, what, types, value=nil, klass=nil) case how when :xpath return element_by_xpath(what) when :css return element_by_css(what) when :ole_object return what end # else: locator = InputElementLocator.new self, types locator.specifier = [how, what, value] locator.document = document return locator.element if locator.fast_locate # todo: restrict search to elements.getElementsByTag('INPUT'); faster locator.elements = ole_inner_elements if locator.elements.nil? locator.klass = klass if klass locator.locate end |
#locate_tagged_element(tag, how, what) ⇒ Object
returns the ole object for the specified element
874 875 876 877 878 |
# File 'lib/watir/container.rb', line 874 def locate_tagged_element(tag, how, what) locator = TaggedElementLocator.new(self, tag) locator.set_specifier(how, what) locator.locate end |
#log(what) ⇒ Object
Write the specified string to the log.
42 43 44 |
# File 'lib/watir/container.rb', line 42 def log(what) @container.logger.debug(what) if @logger end |
#map(how, what = nil) ⇒ Object
This is the main method for accessing map tags - msdn.microsoft.com/workshop/author/dhtml/reference/objects/map.asp?frame=true
* how - symbol - how we access the map,
* what - string, integer or regular expression - what we are looking for,
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a map object
Typical Usage
browser.map(:id, /list/) # access the first map that matches list.
browser.map(:index,2) # access the second map on the page
browser.map(:title, "A Picture") # access a map using the tooltip text. See http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/title_1.asp?frame=true
541 542 543 |
# File 'lib/watir/container.rb', line 541 def map(how, what=nil) return Map.new(self, how, what) end |
#maps ⇒ Object
this is the main method for accessing the maps iterator.
Returns a maps object
Typical usage:
browser.maps.each { |s| puts s.to_s } # iterate through all the maps on the page
browser.maps[1].to_s # goto the first map on the page
browser.maps.length # show how many maps are on the page.
555 556 557 |
# File 'lib/watir/container.rb', line 555 def maps return Maps.new(self) end |
#modal_dialog(how = nil, what = nil) ⇒ Object
Access a modal web dialog, which is a PageContainer, like IE or Frame. Returns a ModalDialog object.
Typical Usage
browser.modal_dialog # access the modal dialog of ie
browser.modal_dialog(:title, 'Title') # access the modal dialog by title
browser.modal_dialog.modal_dialog # access a modal dialog's modal dialog XXX untested!
This method will not work when Watir/Ruby is run under a service (instead of a user). Note: unlike Watir.attach, this returns before the page is assured to have loaded.
211 212 213 |
# File 'lib/watir/container.rb', line 211 def modal_dialog(how=nil, what=nil) ModalDialog.new(self, how, what) end |
#popup ⇒ Object
This is the main method for accessing JavaScript popups. returns a PopUp object
625 626 627 |
# File 'lib/watir/container.rb', line 625 def popup # BUG this should not be on the container object! PopUp.new(self) end |
#pres ⇒ Object
this is the main method for accessing the ps iterator.
Returns a Pres object
Typical usage:
browser.pres.each { |pre| puts pre.to_s } # iterate through all the pre tags on the page
browser.pres[1].to_s # goto the first pre tag on the page
browser.pres.length # show how many pre tags are on the page.
743 744 745 |
# File 'lib/watir/container.rb', line 743 def pres Pres.new(self) end |
#ps ⇒ Object
this is the main method for accessing the ps iterator.
Returns a Ps object
Typical usage:
browser.ps.each { |p| puts p.to_s } # iterate through all the p tags on the page
browser.ps[1].to_s # goto the first p tag on the page
browser.ps.length # show how many p tags are on the page.
729 730 731 |
# File 'lib/watir/container.rb', line 729 def ps Ps.new(self) end |
#radio(how, what = nil, value = nil) ⇒ Object
This is the main method for accessing a radio button. Usually an <input type = radio>
HTML tag.
* how - symbol - how we access the radio button, :index, :id, :name etc
* what - string, integer or regular expression - what we are looking for,
* value - string - when there are multiple objects with different value attributes, this can be used to find the correct object
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a Radio object
Typical usage
browser.radio(:id, 'send_email') # access the radio button with an id of currency
browser.radio(:name, 'send_copy') # access the radio button with a name of country
browser.radio(:name, /n_/) # access the first radio button whose name matches n_
browser.radio(:index, 2) # access the second radio button on the page (1 based, so the first field is accessed with :index,1)
In many instances, radio buttons on an html page have the same name, but are identified by different values. An example is shown next.
<input type="radio" name="email_frequency" value="daily">Daily Email</input>
<input type="radio" name="email_frequency" value="weekly">Weekly Email</input>
<input type="radio" name="email_frequency" value="monthly">Monthly Email</input>
Watir can access these using the following:
browser.radio(:id, 'day_to_send', 'monday') # access the radio button with an id of day_to_send and a value of monday
browser.radio(:name,'email_frequency', 'weekly') # access the radio button with a name of email_frequency and a value of 'weekly'
browser.radio(:xpath, "//input[@name='email_frequency' and @value='daily']/") # access the radio button with a name of email_frequency and a value of 'daily'
446 447 448 |
# File 'lib/watir/container.rb', line 446 def radio(how, what=nil, value=nil) Radio.new(self, how, what, value) end |
#radios ⇒ Object
This is the method for accessing the radio buttons iterator. Returns a Radios object
Typical usage:
browser.radios.each { |r| puts r.to_s } # iterate through all the radio buttons on the page
browser.radios[1].to_s # goto the first radio button on the page
browser.radios.length # show how many radio buttons are on the page.
458 459 460 |
# File 'lib/watir/container.rb', line 458 def radios Radios.new(self) end |
#row(how, what = nil) ⇒ Object
this method accesses a table row. how - symbol - how we access the row, valid values are
:id - find the table row with given id.
:xpath - find the table row using xpath query.
returns a TableRow object
191 192 193 |
# File 'lib/watir/container.rb', line 191 def row(how, what=nil) TableRow.new(self, how, what) end |
#rows ⇒ Object
194 195 196 |
# File 'lib/watir/container.rb', line 194 def rows TableRows.new(self) end |
#select_list(how, what = nil) ⇒ Object Also known as: selectBox
This is the main method for accessing a selection list. Usually a <select>
HTML tag.
* how - symbol - how we access the selection list, :index, :id, :name etc
* what - string, integer or regular expression - what we are looking for,
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a SelectList object
Typical usage
browser.select_list(:id, 'currency') # access the select box with an id of currency
browser.select_list(:name, 'country') # access the select box with a name of country
browser.select_list(:name, /n_/) # access the first select box whose name matches n_
browser.select_list(:index, 2) # access the second select box on the page (1 based, so the first field is accessed with :index,1)
browser.select(:xpath, "//select[@id='currency']/") # access the select box with an id of currency
361 362 363 |
# File 'lib/watir/container.rb', line 361 def select_list(how, what=nil) SelectList.new(self, how, what) end |
#select_lists ⇒ Object
this is the method for accessing the select lists iterator. Returns a SelectLists object
Typical usage:
browser.select_lists.each { |s| puts s.to_s } # iterate through all the select boxes on the page
browser.select_lists[1].to_s # goto the first select boxes on the page
browser.select_lists.length # show how many select boxes are on the page.
372 373 374 |
# File 'lib/watir/container.rb', line 372 def select_lists SelectLists.new(self) end |
#set_container(container) ⇒ Object
:nodoc:
63 64 65 66 |
# File 'lib/watir/container.rb', line 63 def set_container container #:nodoc: @container = container @page_container = container.page_container end |
#show_all_objects ⇒ Object
This method shows the available objects on the current page. This is usually only used for debugging or writing new test scripts. This is a nice feature to help find out what HTML objects are on a page when developing a test case using Watir.
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
# File 'lib/watir/container.rb', line 807 def show_all_objects puts "-----------Objects in page -------------" doc = document s = "" props = ["name", "id", "value", "alt", "src"] doc.all.each do |n| begin s += n.invoke("type").to_s.ljust(16) rescue next end props.each do |prop| begin p = n.invoke(prop) s += " " + "#{prop}=#{p}".to_s.ljust(18) rescue # this object probably doesnt have this property end end s += "\n" end puts s end |
#spans ⇒ Object
this is the main method for accessing the spans iterator.
Returns a Spans object
Typical usage:
browser.spans.each { |s| puts s.to_s } # iterate through all the spans on the page
browser.spans[1].to_s # goto the first span on the page
browser.spans.length # show how many spans are on the page.
700 701 702 |
# File 'lib/watir/container.rb', line 700 def spans Spans.new(self) end |
#strongs ⇒ Object
this is the main method for accessing the Strongs iterator.
Returns a Strongs object
Typical usage:
browser.strongs.each { |s| puts s.to_s } # iterate through all the strongs on the page
browser.strongs[1].to_s # goto the first strong on the page
browser.strongs.length # show how many strongs are on the page.
714 715 716 |
# File 'lib/watir/container.rb', line 714 def strongs return Strongs.new(self) end |
#table(how, what = nil) ⇒ Object
This method is used to get a table from the page. :index (1 based counting) and :id are supported.
NOTE :name is not supported, as the table tag does not have a name attribute. It is not part of the DOM.
:index can be used when there are multiple tables on a page. :xpath can be used to select table using XPath query. The first form can be accessed with :index 1, the second :index 2, etc.
* how - symbol - how we access the table, :index, :id, :xpath etc
* what - string the thing we are looking for, ex. id, index or xpath query, of the object we are looking for
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a Table object
157 158 159 |
# File 'lib/watir/container.rb', line 157 def table(how, what=nil) Table.new(self, how, what) end |
#tables ⇒ Object
this is the main method for accessing the tables iterator. It returns a Tables object
Typical usage:
browser.tables.each { |t| puts t.to_s } # iterate through all the tables on the page
browser.tables[1].to_s # goto the first table on the page
browser.tables.length # show how many tables are on the page. Tables that are nested will be included in this
168 169 170 |
# File 'lib/watir/container.rb', line 168 def tables Tables.new(self) end |
#text_field(how, what = nil) ⇒ Object Also known as: textField
This is the main method for accessing a text field. Usually an <input type=text>
HTML tag. or a text area - a <textarea>
tag
* how - symbol - how we access the field, :index, :id, :name etc
* what - string, integer or regular expression - what we are looking for,
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a TextField object
Typical Usage
browser.text_field(:id, 'user_name') # access the text field with an ID of user_name
browser.text_field(:name, 'address') # access the text field with a name of address
browser.text_field(:index, 2) # access the second text field on the page (1 based, so the first field is accessed with :index,1)
browser.text_field(:xpath, "//textarea[@id='user_name']/") # access the text field with an ID of user_name
301 302 303 |
# File 'lib/watir/container.rb', line 301 def text_field(how, what=nil) TextField.new(self, how, what) end |
#text_fields ⇒ Object
this is the method for accessing the text_fields iterator. It returns a Text_Fields object
Typical usage:
browser.text_fields.each { |t| puts t.to_s } # iterate through all the text fields on the page
browser.text_fields[1].to_s # goto the first text field on the page
browser.text_fields.length # show how many text field are on the page.
312 313 314 |
# File 'lib/watir/container.rb', line 312 def text_fields TextFields.new(self) end |
#wait(no_sleep = false) ⇒ Object Also known as: waitForIE
Wait until Browser has finished loading the page. – called explicitly by most click and set methods
49 50 51 |
# File 'lib/watir/container.rb', line 49 def wait(no_sleep=false) @container.wait(no_sleep) end |