Class: FireWatir::Document
- Inherits:
-
Object
- Object
- FireWatir::Document
- Includes:
- Container
- Defined in:
- lib/firewatir/document.rb
Overview
Description:
Class for returning the document element.
Constant Summary collapse
- @@current_level =
0
Constants included from Container
Container::DEFAULT_HIGHLIGHT_COLOR, Container::MACHINE_IP
Instance Method Summary collapse
-
#[](n) ⇒ Object
Description: Gets the element at the nth index in the array of the elements.
-
#all ⇒ Object
Description: Find all the elements in the document by querying DOM.
-
#each ⇒ Object
Description: Iterates over elements in the document.
- #frames ⇒ Object
-
#get_divs ⇒ Object
Description: Get all divs available on the page.
-
#get_forms ⇒ Object
Description: Get all forms available on the page.
-
#get_images ⇒ Object
Description: Get all images available on the page.
-
#get_labels ⇒ Object
Description: Get all labels available on the page.
-
#get_links ⇒ Object
Description: Get all links available on the page.
-
#get_pres ⇒ Object
Description: Get all pres available on the page.
-
#get_spans ⇒ Object
Description: Get all spans available on the page.
-
#get_tables ⇒ Object
Description: Get all tables available on the page.
-
#initialize(container) ⇒ Document
constructor
Description: Creates new instance of Document class.
-
#length ⇒ Object
(also: #size)
Description: Returns the count of elements in the document.
Methods included from Container
#button, #cell, #checkbox, #dd, #dl, #dt, #file_field, #form, #frame, #hidden, #image, #link, #radio, #row, #select_list, #show_all_objects, #table, #text_field
Methods included from JsshSocket
#js_eval, #js_eval_method, #jssh_socket, #read_socket
Constructor Details
#initialize(container) ⇒ Document
Description:
Creates new instance of Document class.
14 15 16 17 18 19 |
# File 'lib/firewatir/document.rb', line 14 def initialize(container) @length = 0 @elements = nil @arr_elements = "" @container = container end |
Instance Method Details
#[](n) ⇒ Object
Description:
Gets the element at the nth index in the array of the elements.
Input:
n - Index of element you want to access. Index is 1 based.
Output:
Element at the nth index.
131 132 133 |
# File 'lib/firewatir/document.rb', line 131 def [](n) return Element.new("#{@arr_elements}[#{n-1}]", @container) end |
#all ⇒ Object
Description:
Find all the elements in the document by querying DOM.
Set the class variables like length and the variable name of array storing the elements in JSSH.
Output:
Array of elements.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/firewatir/document.rb', line 53 def all @arr_elements = "arr_coll_#{@@current_level}" jssh_command = "var arr_coll_#{@@current_level}=new Array(); " if(@container.class == FireWatir::Firefox || @container.class == Frame) jssh_command <<"var element_collection = null; element_collection = #{@container.document_var}.getElementsByTagName(\"*\"); if(element_collection != null && typeof(element_collection) != 'undefined') { for (var i = 0; i < element_collection.length; i++) { if((element_collection[i].tagName != 'BR') && (element_collection[i].tagName != 'HR') && (element_collection[i].tagName != 'DOCTYPE') && (element_collection[i].tagName != 'META') && (typeof(element_collection[i].tagName) != 'undefined')) arr_coll_#{@@current_level}.push(element_collection[i]); } } arr_coll_#{@@current_level}.length;" else jssh_command <<"var element_collection = null; element_collection = #{@container.element_name}.getElementsByTagName(\"*\"); if(element_collection!= null && typeof(element_collection) != 'undefined') { for (var i = 0; i < element_collection.length; i++) { if((element_collection[i].tagName != 'BR') && (element_collection[i].tagName != 'HR') && (element_collection[i].tagName != 'DOCTYPE') && (element_collection[i].tagName != 'META') && (typeof(element_collection[i].tagName) != 'undefined')) arr_coll_#{@@current_level}.push(element_collection[i]); } } arr_coll_#{@@current_level}.length;" end # Remove \n that are there in the string as a result of pressing enter while formatting. jssh_command.gsub!(/\n/, "") #puts jssh_command jssh_socket.send("#{jssh_command};\n", 0) @length = read_socket().to_i; #puts "elements length is in locate_tagged_elements is : #{@length}" elements = nil elements = Array.new(@length) for i in 0..@length - 1 do temp = Element.new("arr_coll_#{@@current_level}[#{i}]", @container) elements[i] = temp end @@current_level += 1 return elements end |
#each ⇒ Object
Description:
Iterates over elements in the document.
115 116 117 118 119 |
# File 'lib/firewatir/document.rb', line 115 def each for i in 0..@length - 1 yield Element.new("#{@arr_elements}[#{i}]", @container) end end |
#frames ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/firewatir/document.rb', line 21 def frames jssh_command = "var frameset = #{@container.window_var}.frames; var elements_frames = new Array(); for(var i = 0; i < frameset.length; i++) { var frames = frameset[i].frames; for(var j = 0; j < frames.length; j++) { elements_frames.push(frames[j].frameElement); } } elements_frames.length;" jssh_command.gsub!("\n", "") $jssh_socket.send("#{jssh_command};\n", 0) length = read_socket().to_i frame_array = Array.new(length) for i in 0..length - 1 do frame_array[i] = Frame.new(self, :jssh_name, "elements_frames[#{i}]") end frame_array end |
#get_divs ⇒ Object
Description:
Get all divs available on the page.
Used internally by Firewatir use ff.show_divs instead.
Output:
Array containing Div elements
186 187 188 |
# File 'lib/firewatir/document.rb', line 186 def get_divs return Divs.new(@container) end |
#get_forms ⇒ Object
Description:
Get all forms available on the page.
Used internally by Firewatir use ff.show_forms instead.
Output:
Array containing Form elements
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/firewatir/document.rb', line 143 def get_forms() jssh_socket.send("var element_forms = #{@container.document_var}.forms; element_forms.length;\n", 0) length = read_socket().to_i forms = Array.new(length) for i in 0..length - 1 do forms[i] = Form.new(@container, :jssh_name, "element_forms[#{i}]") end return forms end |
#get_images ⇒ Object
Description:
Get all images available on the page.
Used internally by Firewatir use ff.show_images instead.
Output:
Array containing Image elements
162 163 164 |
# File 'lib/firewatir/document.rb', line 162 def get_images return Images.new(@container) end |
#get_labels ⇒ Object
Description:
Get all labels available on the page.
Used internally by Firewatir use ff.show_labels instead.
Output:
Array containing Label elements
234 235 236 |
# File 'lib/firewatir/document.rb', line 234 def get_labels return Labels.new(@container) end |
#get_links ⇒ Object
Description:
Get all links available on the page.
Used internally by Firewatir use ff.show_links instead.
Output:
Array containing Link elements
174 175 176 |
# File 'lib/firewatir/document.rb', line 174 def get_links return Links.new(@container) end |
#get_pres ⇒ Object
Description:
Get all pres available on the page.
Used internally by Firewatir use ff.show_pres instead.
Output:
Array containing Pre elements
210 211 212 |
# File 'lib/firewatir/document.rb', line 210 def get_pres return Pres.new(@container) end |
#get_spans ⇒ Object
Description:
Get all spans available on the page.
Used internally by Firewatir use ff.show_spans instead.
Output:
Array containing Span elements
222 223 224 |
# File 'lib/firewatir/document.rb', line 222 def get_spans return Spans.new(@container) end |
#get_tables ⇒ Object
Description:
Get all tables available on the page.
Used internally by Firewatir use ff.show_tables instead.
Output:
Array containing Table elements
198 199 200 |
# File 'lib/firewatir/document.rb', line 198 def get_tables return Tables.new(@container) end |
#length ⇒ Object Also known as: size
Description:
Returns the count of elements in the document.
Output:
Count of elements found in the document.
106 107 108 |
# File 'lib/firewatir/document.rb', line 106 def length return @length end |