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.
-
#attribute(attribute_name) ⇒ String?
Get the value of the given attribute of the element.
-
#centre ⇒ Object
Get centre coordinates of element.
- #check_exist(timeout = Druid.default_element_wait) ⇒ Object
- #check_visible(timeout = Druid.default_element_wait) ⇒ Object
-
#class_name ⇒ Object
retrieve the class name for an element.
-
#disabled? ⇒ Boolean
return true if the element is not enabled.
-
#height ⇒ Object
Get height of element.
-
#initialize(element) ⇒ Element
constructor
A new instance of Element.
- #inspect ⇒ Object
-
#location ⇒ Object
location of element (x,y).
-
#method_missing(*args, &block) ⇒ Object
delegate calls to driver element.
-
#parent ⇒ Object
Returns parent element of current element.
-
#scroll_into_view ⇒ Object
Scroll until the element is viewable.
-
#size ⇒ Object
size of element (width, height).
-
#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
Waits until the element is not present.
-
#when_not_visible(timeout = Druid.default_element_wait) ⇒ Object
Waits until the element is not visible.
-
#when_present(timeout = Druid.default_element_wait) ⇒ Object
Waits until the element is present.
-
#when_visible(timeout = Druid.default_element_wait) ⇒ Object
Waits until the element is visible.
-
#width ⇒ Object
Get width of element.
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.
16 17 18 19 |
# File 'lib/druid/elements/element.rb', line 16 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
172 173 174 175 |
# File 'lib/druid/elements/element.rb', line 172 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.
14 15 16 |
# File 'lib/druid/elements/element.rb', line 14 def driver @driver end |
#element ⇒ Object
Returns the value of attribute element.
13 14 15 |
# File 'lib/druid/elements/element.rb', line 13 def element @element end |
Instance Method Details
#==(other) ⇒ Boolean
compare this element to another to determine if they are equal
31 32 33 |
# File 'lib/druid/elements/element.rb', line 31 def ==(other) other.is_a? self.class and element == other.element end |
#attribute(attribute_name) ⇒ String?
Get the value of the given attribute of the element
40 41 42 |
# File 'lib/druid/elements/element.rb', line 40 def attribute(attribute_name) element.attribute_value attribute_name end |
#centre ⇒ Object
Get centre coordinates of element
93 94 95 |
# File 'lib/druid/elements/element.rb', line 93 def centre { 'y' => (location['y'] + (size['height']/2)), 'x' => (location['x'] + (size['width']/2)) } end |
#check_exist(timeout = Druid.default_element_wait) ⇒ Object
103 104 105 106 107 |
# File 'lib/druid/elements/element.rb', line 103 def check_exist(timeout=Druid.default_element_wait) timed_loop(timeout) do |element| element.exist? end end |
#check_visible(timeout = Druid.default_element_wait) ⇒ Object
97 98 99 100 101 |
# File 'lib/druid/elements/element.rb', line 97 def check_visible(timeout=Druid.default_element_wait) timed_loop(timeout) do |element| element.visible? end end |
#class_name ⇒ Object
retrieve the class name for an element
47 48 49 |
# File 'lib/druid/elements/element.rb', line 47 def class_name element.class_name end |
#disabled? ⇒ Boolean
return true if the element is not enabled
23 24 25 |
# File 'lib/druid/elements/element.rb', line 23 def disabled? not enabled? end |
#height ⇒ Object
Get height of element
86 87 88 |
# File 'lib/druid/elements/element.rb', line 86 def height size['height'] end |
#inspect ⇒ Object
51 52 53 |
# File 'lib/druid/elements/element.rb', line 51 def inspect element.inspect end |
#location ⇒ Object
location of element (x,y)
65 66 67 |
# File 'lib/druid/elements/element.rb', line 65 def location element.wd.location end |
#parent ⇒ Object
Returns parent element of current element.
111 112 113 114 115 116 |
# File 'lib/druid/elements/element.rb', line 111 def parent parent = element.parent type = element.type if parent.tag_name.to_sym == :input cls = Druid::Elements.element_class_for(parent.tag_name, type) cls.new(parent) end |
#scroll_into_view ⇒ Object
Scroll until the element is viewable
58 59 60 |
# File 'lib/druid/elements/element.rb', line 58 def scroll_into_view element.wd.location_once_scrolled_into_view end |
#size ⇒ Object
size of element (width, height)
72 73 74 |
# File 'lib/druid/elements/element.rb', line 72 def size element.wd.size end |
#wait_until(timeout = Druid.default_element_wait, message = nil, &block) ⇒ Object
Waits until the block returns true
166 167 168 |
# File 'lib/druid/elements/element.rb', line 166 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
Waits until the element is not present
timing out
135 136 137 |
# File 'lib/druid/elements/element.rb', line 135 def when_not_present(timeout=Druid.default_element_wait) element.wait_while(timeout: timeout, message: "Element still present after #{timeout} seconds", &:present?) end |
#when_not_visible(timeout = Druid.default_element_wait) ⇒ Object
Waits until the element is not visible
155 156 157 158 159 |
# File 'lib/druid/elements/element.rb', line 155 def when_not_visible(timeout=Druid.default_element_wait) when_present(timeout) element.wait_while(timeout: timeout, message: "Element still visible after #{timeout} seconds", &:visible?) self end |
#when_present(timeout = Druid.default_element_wait) ⇒ Object
Waits until the element is present
timing out
124 125 126 127 |
# File 'lib/druid/elements/element.rb', line 124 def when_present(timeout=Druid.default_element_wait) element.wait_until(timeout: timeout, message: "Element not present in #{timeout} seconds", &:present?) self end |
#when_visible(timeout = Druid.default_element_wait) ⇒ Object
Waits until the element is visible
144 145 146 147 148 |
# File 'lib/druid/elements/element.rb', line 144 def when_visible(timeout=Druid.default_element_wait) when_present(timeout) element.wait_until(timeout: timeout, message: "Element not visible in #{timeout} seconds", &:visible?) self end |
#width ⇒ Object
Get width of element
79 80 81 |
# File 'lib/druid/elements/element.rb', line 79 def width size['width'] end |