Class: Druid::Elements::Element
- Inherits:
-
Object
- Object
- Druid::Elements::Element
- Includes:
- Assist, NestedElements
- Defined in:
- lib/druid/elements/element.rb
Overview
Contains functionality that is common across all elements
Direct Known Subclasses
Area, Bold, Button, Canvas, CheckBox, Div, FileField, Form, Heading, HiddenField, Image, Italic, Label, Link, ListItem, Media, Option, OrderedList, Paragraph, RadioButton, SelectList, Span, Table, TableCell, TableRow, TextArea, TextField, UnOrderedList
Instance Attribute Summary collapse
-
#driver ⇒ Object
Returns the value of attribute driver.
-
#element ⇒ Object
Returns the value of attribute element.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
compare this element to another to determine if they are equal.
-
#check_exist(timeout = Druid.default_element_wait) ⇒ Object
alias_method :when_present, :check_visible alias_method :when_visible, :check_visible.
- #check_visible(timeout = Druid.default_element_wait) ⇒ Object
-
#children(opt = {}) ⇒ Object
Return all elements that are children of this element.
-
#disabled? ⇒ Boolean
return true if the element is not enabled.
-
#following_sibling(opt = {}) ⇒ Object
Return the element that exists at the same level of the DOM immediately after this element.
-
#following_siblings(opt = {}) ⇒ Object
Return all elements that exist at the same level of the DOM immediately after this element.
-
#initialize(element) ⇒ Element
constructor
A new instance of Element.
-
#method_missing(*args, &block) ⇒ Object
delegate calls to driver element.
- #name ⇒ Object
-
#parent(opt = {}) ⇒ Object
find the parent element.
-
#preceding_sibling(opt = {}) ⇒ Object
Return the element that exists at the same level of the DOM immediately prior to this element.
-
#preceding_siblings(opt = {}) ⇒ Object
Return all elements that exist at the same level of the DOM immediately prior to this element.
-
#present? ⇒ Boolean
return true if the element exists and is visible.
- #respond_to_missing?(m, *args) ⇒ Boolean
-
#siblings(opt = {}) ⇒ Object
Return all elements that are direct children of this element’s parent.
-
#wait_until(timeout = Druid.default_element_wait, message = nil, &block) ⇒ Object
Waits until the block returns true.
-
#when_not_present(timeout = Druid.default_element_wait) ⇒ Object
(also: #when_not_visible)
Waits until the element is not present.
-
#when_present(timeout = Druid.default_element_wait) ⇒ Object
(also: #when_visible)
Wait until the element is present.
Methods included from Assist
#area_for, #areas_for, #audio_for, #audios_for, #b_for, #b_text_for, #bs_for, #button_for, #buttons_for, #canvas_for, #canvass_for, #cell_for, #cell_text_for, #cells_for, #check_checkbox, #checkbox_checked?, #checkbox_for, #checkboxs_for, #click_area_for, #click_button_for, #click_link_for, #div_for, #div_text_for, #divs_for, #element_for, #elements_for, #file_field_for, #file_field_value_set, #file_fields_for, #form_for, #forms_for, #h1_for, #h1_text_for, #h1s_for, #h2_for, #h2_text_for, #h2s_for, #h3_for, #h3_text_for, #h3s_for, #h4_for, #h4_text_for, #h4s_for, #h5_for, #h5_text_for, #h5s_for, #h6_for, #h6_text_for, #h6s_for, #hidden_field_for, #hidden_field_value_for, #hidden_fields_for, #i_for, #i_text_for, #image_for, #image_loaded_for, #images_for, #is_for, #label_for, #label_text_for, #labels_for, #link_for, #links_for, #list_item_for, #list_item_text_for, #list_items_for, #ordered_list_for, #ordered_list_text_for, #ordered_lists_for, #page_for, #pages_for, #paragraph_for, #paragraph_text_for, #paragraphs_for, #radio_button_for, #radio_buttons_for, #radio_selected?, #row_for, #row_text_for, #rows_for, #select_list_for, #select_list_value_for, #select_list_value_set, #select_lists_for, #select_radio, #span_for, #span_text_for, #spans_for, #svg_for, #svgs_for, #table_for, #table_text_for, #tables_for, #text_area_for, #text_area_value_for, #text_area_value_set, #text_areas_for, #text_field_for, #text_field_value_for, #text_field_value_set, #text_fields_for, #uncheck_checkbox, #unordered_list_for, #unordered_list_text_for, #unordered_lists_for, #video_for, #videos_for
Methods included from NestedElements
Constructor Details
#initialize(element) ⇒ Element
Returns a new instance of Element.
15 16 17 18 |
# File 'lib/druid/elements/element.rb', line 15 def initialize(element) @element = element @driver = @element end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
delegate calls to driver element
156 157 158 159 |
# File 'lib/druid/elements/element.rb', line 156 def method_missing(*args, &block) m = args.shift element.send m, *args, &block end |
Instance Attribute Details
#driver ⇒ Object
Returns the value of attribute driver.
13 14 15 |
# File 'lib/druid/elements/element.rb', line 13 def driver @driver end |
#element ⇒ Object
Returns the value of attribute element.
12 13 14 |
# File 'lib/druid/elements/element.rb', line 12 def element @element end |
Instance Method Details
#==(other) ⇒ Boolean
compare this element to another to determine if they are equal
37 38 39 |
# File 'lib/druid/elements/element.rb', line 37 def ==(other) other.is_a? self.class and element == other.element end |
#check_exist(timeout = Druid.default_element_wait) ⇒ Object
alias_method :when_present, :check_visible alias_method :when_visible, :check_visible
50 51 52 53 54 55 |
# File 'lib/druid/elements/element.rb', line 50 def check_exist(timeout=Druid.default_element_wait) timed_loop(timeout) do |element| element.exists? end # wait_until(timeout: timeout, &:exist?) end |
#check_visible(timeout = Druid.default_element_wait) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/druid/elements/element.rb', line 41 def check_visible(timeout=Druid.default_element_wait) timed_loop(timeout) do |element| element.present? end # wait_until(timeout: timeout, message: "Element not visible in #{timeout} seconds", &:present?) end |
#children(opt = {}) ⇒ Object
Return all elements that are children of this element
94 95 96 97 |
# File 'lib/druid/elements/element.rb', line 94 def children(opt={}) children = element.children(opt) children.collect {|child| druid_wrapper(child)} end |
#disabled? ⇒ Boolean
return true if the element is not enabled
22 23 24 |
# File 'lib/druid/elements/element.rb', line 22 def disabled? not enabled? end |
#following_sibling(opt = {}) ⇒ Object
Return the element that exists at the same level of the DOM immediately after this element
78 79 80 81 |
# File 'lib/druid/elements/element.rb', line 78 def following_sibling(opt={}) sibling = element.following_sibling(opt) druid_wrapper(sibling) end |
#following_siblings(opt = {}) ⇒ Object
Return all elements that exist at the same level of the DOM immediately after this element
112 113 114 115 |
# File 'lib/druid/elements/element.rb', line 112 def following_siblings(opt={}) siblings = element.following_siblings(opt) siblings.collect {|sibling| druid_wrapper(sibling)} end |
#name ⇒ Object
150 151 152 |
# File 'lib/druid/elements/element.rb', line 150 def name element.attribute(:name) end |
#parent(opt = {}) ⇒ Object
find the parent element
60 61 62 63 |
# File 'lib/druid/elements/element.rb', line 60 def parent(opt = {}) parent = element.parent(opt) druid_wrapper(parent) end |
#preceding_sibling(opt = {}) ⇒ Object
Return the element that exists at the same level of the DOM immediately prior to this element
69 70 71 72 |
# File 'lib/druid/elements/element.rb', line 69 def preceding_sibling(opt = {}) sibling = element.preceding_sibling(opt) druid_wrapper(sibling) end |
#preceding_siblings(opt = {}) ⇒ Object
Return all elements that exist at the same level of the DOM immediately prior to this element
103 104 105 106 |
# File 'lib/druid/elements/element.rb', line 103 def preceding_siblings(opt={}) siblings = element.preceding_siblings(opt) siblings.collect {|sibling| druid_wrapper(sibling)} end |
#present? ⇒ Boolean
return true if the element exists and is visible
29 30 31 |
# File 'lib/druid/elements/element.rb', line 29 def present? element.present? end |
#respond_to_missing?(m, *args) ⇒ Boolean
161 162 163 |
# File 'lib/druid/elements/element.rb', line 161 def respond_to_missing?(m,*args) element.respond_to?(m) || super end |
#siblings(opt = {}) ⇒ Object
Return all elements that are direct children of this element’s parent
86 87 88 89 |
# File 'lib/druid/elements/element.rb', line 86 def siblings(opt={}) siblings = element.siblings(opt) siblings.collect {|sibling| druid_wrapper(sibling)} end |
#wait_until(timeout = Druid.default_element_wait, message = nil, &block) ⇒ Object
Waits until the block returns true
146 147 148 |
# File 'lib/druid/elements/element.rb', line 146 def wait_until(timeout=Druid.default_element_wait, =nil, &block) element.wait_until(timeout: timeout, message: , &block) end |
#when_not_present(timeout = Druid.default_element_wait) ⇒ Object Also known as: when_not_visible
Waits until the element is not present
timing out
134 135 136 |
# File 'lib/druid/elements/element.rb', line 134 def when_not_present(timeout=Druid.default_element_wait) element.wait_while(timeout: timeout, message: "Element still present in #{timeout} seconds", &:present?) end |
#when_present(timeout = Druid.default_element_wait) ⇒ Object Also known as: when_visible
Wait until the element is present
122 123 124 125 |
# File 'lib/druid/elements/element.rb', line 122 def when_present(timeout=Druid.default_element_wait) element.wait_until(timeout: timeout, message: "Element not present in #{timeout} seconds", &:present?) self end |